Class: RussianWorkdays::Day

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

Instance Method Summary collapse

Constructor Details

#initialize(date) ⇒ Day

Returns a new instance of Day.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/russian_workdays/day.rb', line 9

def initialize(date)
  @date = date
  raise ArgumentError, "Must be a Date object" unless @date.is_a?(::Date)
  raise ArgumentError, "Data missing for that year" unless DATES.key?(@date.year)
end

Instance Method Details

#holiday?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/russian_workdays/day.rb', line 15

def holiday?
  !preholiday? && (weekend? || DATES[@date.year][:holidays].include?(@date))
end

#preholiday?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/russian_workdays/day.rb', line 19

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

#typeObject



27
28
29
30
31
# File 'lib/russian_workdays/day.rb', line 27

def type
  return :holiday if holiday?
  return :preholiday if preholiday?
  return :work if work?
end

#work?Boolean

Returns:

  • (Boolean)


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

def work?
  !holiday?
end