Skip to content

Commit

Permalink
add error message
Browse files Browse the repository at this point in the history
  • Loading branch information
4geru committed Oct 29, 2024
1 parent ad0b908 commit 85d120a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/sg_strange_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(year, today = nil)
end

def generate(vertical: false)
return invalid_message unless valid?
# [
# %w[year Su Mo Tu We Th Fr ... Sa Su Mo]
# [Mon, nil, nil, ... Date1, Date2, ... Date31, nil, nil, ...]]
Expand All @@ -28,4 +29,23 @@ def generate(vertical: false)
)
end
end

private

def invalid_message
year = 1996
today = Date.new(1996, 3, 2)
table = SgStrangeCalendar::Table.new(year, today).generate
"\n==== error === invalid === year ====" \
+ "\n\n" + ("🎂" * 40) + "\n\n" \
+ SgStrangeCalendar::Presenter::HorizonalPresenter.new.present(
table,
today) \
+ "\n\n" + ("🎂" * 40) \
+ "\n\n" + "しげるの誕生日は 1996年3月2日 です!\n"
end

def valid?
1000 <= @year && @year <= 9999
end
end

0 comments on commit 85d120a

Please sign in to comment.