Class: SwedishHolidays::Holiday

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/swedish_holidays/holiday.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr) ⇒ Holiday

Returns a new instance of Holiday.



58
59
60
61
# File 'lib/swedish_holidays/holiday.rb', line 58

def initialize(attr)
  @date = Date.parse(attr[:datum])
  @name = attr[:namn]
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



12
13
14
# File 'lib/swedish_holidays/holiday.rb', line 12

def date
  @date
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/swedish_holidays/holiday.rb', line 12

def name
  @name
end

Class Method Details

.each(year = Date.today.year) ⇒ Object



25
26
27
28
29
30
# File 'lib/swedish_holidays/holiday.rb', line 25

def each(year = Date.today.year)
  load(year)
  holidays = loaded[year.to_i].values
  return holidays.each unless block_given?
  holidays.each { |holiday| yield holiday }
end

.find(date) ⇒ Object



19
20
21
22
23
# File 'lib/swedish_holidays/holiday.rb', line 19

def find(date)
  year = date.year
  load(year)
  loaded[year][date.yday]
end

.holiday?(date) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/swedish_holidays/holiday.rb', line 15

def holiday?(date)
  !find(date).nil?
end

Instance Method Details

#<=>(other) ⇒ Object



65
66
67
# File 'lib/swedish_holidays/holiday.rb', line 65

def <=>(other)
  date <=> other.date
end

#to_sObject



69
70
71
# File 'lib/swedish_holidays/holiday.rb', line 69

def to_s
  "#{date.strftime}: #{name}"
end