Class: RussianWorkdays::Day
- Inherits:
-
Object
- Object
- RussianWorkdays::Day
- Defined in:
- lib/russian_workdays/day.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
Instance Method Summary collapse
- #holiday? ⇒ Boolean
-
#initialize(date) ⇒ Day
constructor
A new instance of Day.
- #preholiday? ⇒ Boolean
- #to_date ⇒ Object
- #type ⇒ Object
- #work? ⇒ Boolean
Constructor Details
#initialize(date) ⇒ Day
Returns a new instance of Day.
9 10 11 12 13 14 |
# File 'lib/russian_workdays/day.rb', line 9 def initialize(date) raise ArgumentError, 'Must be a Date object' unless date.is_a?(::Date) raise MissingYearError, date.year unless DATES.key?(date.year) @date = date end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
7 8 9 |
# File 'lib/russian_workdays/day.rb', line 7 def date @date end |
Instance Method Details
#holiday? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/russian_workdays/day.rb', line 16 def holiday? return true if DATES[date.year][:holidays].include?(date) !preholiday? && weekend? end |
#preholiday? ⇒ Boolean
22 23 24 |
# File 'lib/russian_workdays/day.rb', line 22 def preholiday? DATES[date.year][:preholidays].include?(date) end |
#to_date ⇒ Object
37 38 39 |
# File 'lib/russian_workdays/day.rb', line 37 def to_date date end |
#type ⇒ Object
30 31 32 33 34 35 |
# File 'lib/russian_workdays/day.rb', line 30 def type return :holiday if holiday? return :preholiday if preholiday? :work if work? end |
#work? ⇒ Boolean
26 27 28 |
# File 'lib/russian_workdays/day.rb', line 26 def work? !holiday? end |