Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix holiday names format

  • Loading branch information...
commit cf37a717c1bd79a8855f89b87fb47ff31c3228bf 1 parent e3902c4
kyoendo authored
Showing with 15 additions and 4 deletions.
  1. +11 −4 lib/month.rb
  2. +4 −0 test/tc_month.rb
15 lib/month.rb
View
@@ -44,7 +44,7 @@ def format(style=:block, from=0, color=false, footer=true)
three_columns_formatter[months, from, color]
else raise ArgumentError
end
- footer ? body + holiday_names(style==:block3 ? months.map(&:month) : Array(@month)) : body
+ footer ? body + holiday_names(style==:block3 ? months : Array(self)) : body
end
def color_format(style=:block, from=0, footer=true)
@@ -161,9 +161,16 @@ def week_label(from, style)
end
def holiday_names(months)
- return [] unless @@holidays[@year][@code]
- @@holidays[@year][@code].select { |d, _| months.include? d.mon }.sort_by { |d, _| d }
- .map { |date, name| date.strftime('%_m/%_d').yellow + ": " + name.green }
+ months.inject([]) { |mem, mon|
+ holidays = @@holidays[mon.year][@code].select { |d, _| d.mon == mon.month }
+ if holidays.empty?
+ mem
+ else
+ mem << holidays.sort_by { |d, _| d }
+ .map { |date, name| date.strftime('%_m/%_d').yellow + ": " + name.green }
+ .join
+ end
+ }
end
end
end
4 test/tc_month.rb
View
@@ -98,5 +98,9 @@ def test_holiday_label_with_different_style
puts m.color_format(:block, 0)
puts m.color_format(:line, 0)
puts m.color_format(:block3, 0)
+ m2 = Caline::Month.new(2009, 5)
+ m2.holidays = :ja_ja
+ puts m2.color_format(:block, 0)
+ puts m2.color_format(:block3, 1)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.