Class: HolidayJp::Holidays

Inherits:
Object
  • Object
show all
Defined in:
lib/holiday_jp/holidays.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHolidays

Returns a new instance of Holidays.



7
8
9
10
11
12
13
# File 'lib/holiday_jp/holidays.rb', line 7

def initialize
  @holidays = {}
  yaml = YAML.load_file(File.expand_path("../../../holidays.yml", __FILE__))
  yaml.map do |key, value|
    @holidays[key] = Holiday.new(key, value)
  end
end

Instance Attribute Details

#holidaysObject

Returns the value of attribute holidays.



5
6
7
# File 'lib/holiday_jp/holidays.rb', line 5

def holidays
  @holidays
end

Instance Method Details

#between(start, last) ⇒ Object



15
16
17
18
19
# File 'lib/holiday_jp/holidays.rb', line 15

def between(start, last)
  holidays.find_all do |date, _holiday|
    start <= date && date <= last
  end.map(&:last)
end

#holiday?(date) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/holiday_jp/holidays.rb', line 21

def holiday?(date)
  holidays[date]
end