Class: RussianWorkdays::Day

Inherits:
Object
  • Object
show all
Defined in:
lib/russian_workdays/day.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ Day

Returns a new instance of Day.

Raises:

  • (ArgumentError)


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

#dateObject (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

Returns:

  • (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

Returns:

  • (Boolean)


22
23
24
# File 'lib/russian_workdays/day.rb', line 22

def preholiday?
  DATES[date.year][:preholidays].include?(date)
end

#to_dateObject



37
38
39
# File 'lib/russian_workdays/day.rb', line 37

def to_date
  date
end

#typeObject



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

Returns:

  • (Boolean)


26
27
28
# File 'lib/russian_workdays/day.rb', line 26

def work?
  !holiday?
end