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
14
15
16
17
18
19
# File 'lib/holiday_jp/holidays.rb', line 7

def initialize
  @holidays = {}
  yaml = {}
  file = File.expand_path("../../../holidays.yml", __FILE__)
  if YAML.respond_to?(:unsafe_load_file)
    yaml = YAML.unsafe_load_file(file)
  else
    yaml = YAML.load_file(file)
  end
  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



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

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

#holiday?(date) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/holiday_jp/holidays.rb', line 27

def holiday?(date)
  holidays.has_key?(date.to_date)
end