Skip to content

Commit

Permalink
Revert "Fix level 2"
Browse files Browse the repository at this point in the history
This reverts commit 5806c25.
  • Loading branch information
tttol committed Nov 9, 2024
1 parent 558d60a commit 778b5b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
33 changes: 8 additions & 25 deletions lib/sg_strange_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ class SgStrangeCalendar
def initialize(year, today = nil)
@year = year
@today = today
@calendar = create_calendar_hash(year) # {"Jan" => {1 => "Mo", 2=>"Tu", ... }, "Feb"=>{1=>"Th", ... }, ...}
@calendar = generate_calendar_hash(year) # {"Jan" => {1 => "Mo", 2=>"Tu", ... }, "Feb"=>{1=>"Th", ... }, ...}
end

def generate(vertical: false)
result = [@year.to_s + " " + WEEKDAY_HEADER]
@calendar.each do |month, date|
result.push(create_month_line(month, date))
end
adjust_space(result.join("\n"))
puts result
result.join("\n")
end

def create_calendar_hash(year)
def generate_calendar_hash(year)
result = {}

Date.new(year, 1, 1).step(Date.new(year, 12, 31)).each do |date|
Expand All @@ -31,7 +32,7 @@ def create_calendar_hash(year)
end

def create_month_line(month, date)
result = [month.ljust(4)]
result = [month + " "]
target_date = 1

WEEKDAY_HEADER.split(" ").each do |w|
Expand All @@ -41,11 +42,7 @@ def create_month_line(month, date)
end

if w == target_weekday
if isToday(month, target_date)
result.push("[" + target_date.to_s + "]")
else
result.push(target_date.to_s.rjust(2))
end
result.push(target_date.to_s.rjust(2))
target_date += 1
else
result.push(" ")
Expand All @@ -54,21 +51,7 @@ def create_month_line(month, date)

result.join(" ")
end

def isToday(targe_month, target_date)
!@today.nil? && @today.strftime("%Y") == @year.to_s && @today.strftime("%b") == targe_month && @today.strftime("%d") == target_date.to_s.rjust(2, "0")
end
end

def adjust_space(target)
if @today.nil?
return target
end

@today.strftime("%d").to_i < 10 ? target.gsub("] ", "]") : target.gsub(" [", "[").gsub("] ", "]")

end

today = Date.new(2024, 12, 31)
c = SgStrangeCalendar.new(2024, today)
c.generate
# c = SgStrangeCalendar.new(2025)
# c.generate
2 changes: 2 additions & 0 deletions test/sg_strange_calendar_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_level_2_for_2024_01_01
end

def test_level_2_for_2024_12_09
skip "レベル2にチャレンジする人はこの行を削除してください"
expected = <<~TXT.chomp
2024 Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo
Jan 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Expand All @@ -87,6 +88,7 @@ def test_level_2_for_2024_12_09
end

def test_level_2_for_2025_03_31
skip "レベル2にチャレンジする人はこの行を削除してください"
expected = <<~TXT.chomp
2025 Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo
Jan 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Expand Down

0 comments on commit 778b5b2

Please sign in to comment.