Skip to content

calender command#589

Open
daiki03130 wants to merge 1 commit intofjordllc:mainfrom
daiki03130:02-calender
Open

calender command#589
daiki03130 wants to merge 1 commit intofjordllc:mainfrom
daiki03130:02-calender

Conversation

@daiki03130
Copy link
Copy Markdown

@daiki03130 daiki03130 commented Apr 2, 2026

Summary by CodeRabbit

リリースノート

  • 新機能
    • カレンダー表示ツールを追加しました。コマンドラインオプションで月と年を指定して、フォーマット済みのカレンダーを表示できます。デフォルトでは現在の月が表示されます。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

ウォークスルー

月と年の初期値を現在の日付から設定し、--month/-mおよび--year/-yコマンドラインフラグをOptionParserで解析する新しいRubyスクリプトが追加されます。その後、月が1~12、年が1970~2100の範囲内であることを検証し、無効な場合は日本語のエラーメッセージで中止します。指定された月年の最初の曜日を計算してオフセットを決定し、カレンダーをフォーマットして出力します。

変更

コホート / ファイル(s) 概要
新しいカレンダースクリプト
02.calendar/cal.rb
月と年のコマンドラインオプション解析、入力値の検証(月:1~12、年:1970~2100)、曜日の計算、および日本語ヘッダー付きカレンダー出力機能を備えたスタンドアロンCLIプログラムを実装。

推定コードレビュー工数

🎯 2 (Simple) | ⏱️ ~10 分

ポエム

🐰✨ 新しいカレンダーが生まれた、
月と年を自由に選べて、
日本語のヘッダーで優雅に表示、
曜日の計算も完璧さ、
時の流れを映す美しき予定表よ!📅

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは「calender command」ですが、実装されているスクリプトは「calendar」(暦/カレンダー)の機能です。タイトルに「calender」という綴りの誤字があります。内容としてはカレンダーコマンドの実装を示していますが、綴りが正確ではありません。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@02.calendar/cal.rb`:
- Around line 36-46: ループで日付を出力した後、月末が土曜((first_wday + days_in_month) % 7 ==
0)で終わらない場合に改行が足りずプロンプトが同じ行に続いてしまう問題があります。for_each ループ後に (first_wday +
days_in_month) % 7 != 0 を判定して改行を追加するように修正してください(参照変数: days_in_month, first_wday,
n)。
- Around line 9-10: opt.onブロックで m.to_i により「11abc」が 11
として受け取られてしまう問題があるため、月パラメータの厳密な整数パースを行ってください: opt.on(... ) 内の月変数 month を設定する際に m
を Integer(m) で変換するか /^\d+$/ などの正規表現で検証してから Integer
に変換し、不正な文字列ならエラーメッセージを出して処理を中断するように実装してください(参照: opt.on block と変数 month)。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9da5de7b-bd97-490b-9d9a-8b24e5db543d

📥 Commits

Reviewing files that changed from the base of the PR and between 384dc36 and b4b6c94.

📒 Files selected for processing (1)
  • 02.calendar/cal.rb

Comment on lines +9 to +10
opt.on("-m MONTH", "--month MONTH", "受け取った月") do |m|
month = m.to_i
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Ruby の String#to_iInteger(str, 10) の違い(例: "10abc", "2000abc")を公式ドキュメントで確認してください。

💡 Result:

RubyのString#to_iとInteger(str, 10)の主な違いは、文字列が厳密な整数表現に準拠しているかどうかの扱いです。 String#to_i(base = 10): - 文字列の先頭から有効な数字部分のみを解釈し、無効な文字以降を無視します。 - 有効な数字部分がない場合、0を返します。例外を投げません。 例(公式ドキュメントより): - "10abc".to_i → 10 - "2000abc".to_i → 2000 - "0x11".to_i → 0(先頭の"0x"は10進では無効) - "".to_i → 0 Integer(str, base=10) (Kernel#Integer): - 文字列は厳密に数値表現に準拠している必要があります。余分な文字があるとArgumentErrorを投げます。 - String#to_iとは異なり、文字列全体が純粋な整数でなければなりません。 例: - "10".to_i → 10, Integer("10", 10) → 10 - "10abc".to_i → 10, Integer("10abc", 10) → ArgumentError (invalid value for Integer: "10abc") - "2000abc".to_i → 2000, Integer("2000abc", 10) → ArgumentError これらの動作はRuby 4.0/3.xの公式ドキュメント(docs.ruby-lang.org, ruby-doc.org)で確認され、StackOverflowなどの二次ソースでも一致します。to_iは寛容、Integerは厳格です。

Citations:


🏁 Script executed:

find . -type f -name "cal.rb" | head -20

Repository: fjordllc/ruby-practices

Length of output: 87


🏁 Script executed:

cat -n ./02.calendar/cal.rb

Repository: fjordllc/ruby-practices

Length of output: 1254


to_i により不正な引数文字列が通ってしまいます。

"-m 11abc" のような値が 11 に変換されてしまうため、整数として厳密にパースしてください。

修正案(厳密な整数パース)
 OptionParser.new do |opt|
   opt.on("-m MONTH", "--month MONTH", "受け取った月") do |m|
-    month = m.to_i
+    begin
+      month = Integer(m, 10)
+    rescue ArgumentError
+      abort "月は整数で指定してください"
+    end
   end

   opt.on("-y YEAR", "--year YEAR", "年を指定") do |y|
-    year = y.to_i
+    begin
+      year = Integer(y, 10)
+    rescue ArgumentError
+      abort "年は整数で指定してください"
+    end
   end
 end.parse!
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
opt.on("-m MONTH", "--month MONTH", "受け取った月") do |m|
month = m.to_i
opt.on("-m MONTH", "--month MONTH", "受け取った月") do |m|
begin
month = Integer(m, 10)
rescue ArgumentError
abort "月は整数で指定してください"
end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@02.calendar/cal.rb` around lines 9 - 10, opt.onブロックで m.to_i により「11abc」が 11
として受け取られてしまう問題があるため、月パラメータの厳密な整数パースを行ってください: opt.on(... ) 内の月変数 month を設定する際に m
を Integer(m) で変換するか /^\d+$/ などの正規表現で検証してから Integer
に変換し、不正な文字列ならエラーメッセージを出して処理を中断するように実装してください(参照: opt.on block と変数 month)。

Comment on lines +36 to +46
(1..days_in_month).each do |n|
if n < 10
print " #{n} "
else
print "#{n} "
end

if (first_wday + n) % 7 == 0
print "\n"
end
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

月末が土曜で終わらない場合、出力の最終改行が欠けます。

プロンプトと同じ行に続いてしまうため、ループ後に改行を補ってください。

修正案(最終改行の補完)
 (1..days_in_month).each do |n|
   if n < 10
     print " #{n} "
   else
     print "#{n} "
   end

   if (first_wday + n) % 7 == 0
     print "\n"
   end
 end
+puts unless (first_wday + days_in_month) % 7 == 0
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(1..days_in_month).each do |n|
if n < 10
print " #{n} "
else
print "#{n} "
end
if (first_wday + n) % 7 == 0
print "\n"
end
end
(1..days_in_month).each do |n|
if n < 10
print " #{n} "
else
print "#{n} "
end
if (first_wday + n) % 7 == 0
print "\n"
end
end
puts unless (first_wday + days_in_month) % 7 == 0
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@02.calendar/cal.rb` around lines 36 - 46, ループで日付を出力した後、月末が土曜((first_wday +
days_in_month) % 7 == 0)で終わらない場合に改行が足りずプロンプトが同じ行に続いてしまう問題があります。for_each ループ後に
(first_wday + days_in_month) % 7 != 0 を判定して改行を追加するように修正してください(参照変数:
days_in_month, first_wday, n)。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant