Skip to content
Browse files

fix holiday_names

  • Loading branch information...
1 parent cf37a71 commit 23f858bee769e56b571d7ff6c1c0e808777bb06f @melborne committed Dec 16, 2010
Showing with 53 additions and 53 deletions.
  1. +6 −6 lib/month.rb
  2. +47 −47 test/tc_month.rb
View
12 lib/month.rb
@@ -162,13 +162,13 @@ def week_label(from, style)
def holiday_names(months)
months.inject([]) { |mem, mon|
- holidays = @@holidays[mon.year][@code].select { |d, _| d.mon == mon.month }
- if holidays.empty?
- mem
+ holidays = @@holidays[mon.year][@code]
+ if holidays && !(selected = holidays.select { |d, _| d.mon == mon.month }).empty?
+ mem << selected.sort_by { |d, _| d }
+ .map { |date, name| date.strftime('%_m/%_d').yellow + ": " + name.green }
+ .join
else
- mem << holidays.sort_by { |d, _| d }
- .map { |date, name| date.strftime('%_m/%_d').yellow + ": " + name.green }
- .join
+ mem
end
}
end
View
94 test/tc_month.rb
@@ -41,56 +41,56 @@ def test_dates_by_block
assert_equal(f2010_12_from1, @m.dates_by_block(1).map{ |w| w.map(&:day) })
end
- #def test_format
- #puts
- #puts @m.format
- #puts
- #puts @m.format(:block, 1)
- #puts
- #puts @m.format(:line)
- #end
+ def test_format
+ puts
+ puts @m.format
+ puts
+ puts @m.format(:block, 1)
+ puts
+ puts @m.format(:line)
+ end
- #def test_color_format
- #puts @m.color_format(:block, 0)
- #puts @m.color_format(:block, 1)
- #puts @m.color_format(:line, 1)
- #puts @m.color_format(:block3)
- #end
+ def test_color_format
+ puts @m.color_format(:block, 0)
+ puts @m.color_format(:block, 1)
+ puts @m.color_format(:line, 1)
+ puts @m.color_format(:block3)
+ end
- #def test_colors
- #m = Caline::Month.new(2011, 2, sunday: :yellow, saturday: :green)
- #puts
- #puts m.color_format(:block, 0)
- #m.colors = {sunday: :red, saturday: :blue}
- #puts m.color_format(:line, 1)
- #end
+ def test_colors
+ m = Caline::Month.new(2011, 2, sunday: :yellow, saturday: :green)
+ puts
+ puts m.color_format(:block, 0)
+ m.colors = {sunday: :red, saturday: :blue}
+ puts m.color_format(:line, 1)
+ end
- #def test_holidays
- #months = (1..12).map { |m| Caline::Month.new(2011, m) }
- #months.each do |mon|
- #mon.holidays = :ja_ja
- #puts
- #puts mon.color_format
- #end
- #months.each do |mon|
- #mon.holidays = :us
- #puts
- #puts mon.color_format
- #end
- #end
- #
- #def test_holiday_label_with_different_country
- #m = Caline::Month.new(2010, 4)
- #puts m.color_format(:block, 0)
- #m.holidays = :ja_ja
- #puts m.color_format(:block, 0)
- #m.holidays = :us
- #puts m.color_format(:block, 0)
- #m.holidays = :au
- #puts m.color_format(:block, 0)
- #puts 'no label'
- #puts m.color_format(:block, 0, false)
- #end
+ def test_holidays
+ months = (1..12).map { |m| Caline::Month.new(2011, m) }
+ months.each do |mon|
+ mon.holidays = :ja_ja
+ puts
+ puts mon.color_format
+ end
+ months.each do |mon|
+ mon.holidays = :us
+ puts
+ puts mon.color_format
+ end
+ end
+
+ def test_holiday_label_with_different_country
+ m = Caline::Month.new(2010, 4)
+ puts m.color_format(:block, 0)
+ m.holidays = :ja_ja
+ puts m.color_format(:block, 0)
+ m.holidays = :us
+ puts m.color_format(:block, 0)
+ m.holidays = :au
+ puts m.color_format(:block, 0)
+ puts 'no label'
+ puts m.color_format(:block, 0, false)
+ end
def test_holiday_label_with_different_style
m = Caline::Month.new(2010, 12)

0 comments on commit 23f858b

Please sign in to comment.
Something went wrong with that request. Please try again.