Class: HolidayJp::Holidays
- Inherits:
-
Object
- Object
- HolidayJp::Holidays
- Defined in:
- lib/holiday_jp/holidays.rb
Instance Attribute Summary collapse
-
#holidays ⇒ Object
Returns the value of attribute holidays.
Instance Method Summary collapse
- #between(start, last) ⇒ Object
- #holiday?(date) ⇒ Boolean
-
#initialize ⇒ Holidays
constructor
A new instance of Holidays.
Constructor Details
#initialize ⇒ Holidays
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.("../../../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
#holidays ⇒ Object
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
27 28 29 |
# File 'lib/holiday_jp/holidays.rb', line 27 def holiday?(date) holidays.has_key?(date.to_date) end |