Class: HolidayCo::Year

Inherits:
Object
  • Object
show all
Defined in:
lib/holiday_co/models/year.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year) ⇒ Year

Returns a new instance of Year.



15
16
17
# File 'lib/holiday_co/models/year.rb', line 15

def initialize(year)
  @year = year.to_s
end

Instance Attribute Details

#yearObject (readonly)

Returns the value of attribute year.



13
14
15
# File 'lib/holiday_co/models/year.rb', line 13

def year
  @year
end

Instance Method Details

#holiday_datesObject



32
33
34
# File 'lib/holiday_co/models/year.rb', line 32

def holiday_dates
  holidays.map { |h| h[:date] }
end

#holiday_namesObject



28
29
30
# File 'lib/holiday_co/models/year.rb', line 28

def holiday_names
  holidays.map { |h| h[:name] }
end

#holidaysObject



19
20
21
22
23
24
25
26
# File 'lib/holiday_co/models/year.rb', line 19

def holidays
  raise YearDataNotAvailableError unless year_data_available?

  YAML
    .load_file(File.expand_path("../../../../data/years/#{year}.yml", __FILE__))
    .fetch("holidays", [])
    .map { |h| h.transform_keys(&:to_sym) }
end