Class: SwedishHolidays::Holiday
- Inherits:
-
Object
- Object
- SwedishHolidays::Holiday
- Extended by:
- Forwardable
- Includes:
- Comparable
- Defined in:
- lib/swedish_holidays/holiday.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(attr) ⇒ Holiday
constructor
A new instance of Holiday.
- #to_s ⇒ Object
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
#date ⇒ Object (readonly)
Returns the value of attribute date.
12 13 14 |
# File 'lib/swedish_holidays/holiday.rb', line 12 def date @date end |
#name ⇒ Object (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
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_s ⇒ Object
69 70 71 |
# File 'lib/swedish_holidays/holiday.rb', line 69 def to_s "#{date.strftime}: #{name}" end |