Class: Chinese::Holidays::Days

Inherits:
Object
  • Object
show all
Defined in:
lib/chinese/holidays/days.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, range, type) ⇒ Days

Returns a new instance of Days.



7
8
9
10
11
# File 'lib/chinese/holidays/days.rb', line 7

def initialize(name, range, type)
  @name = name
  @range = range
  @type = type
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/chinese/holidays/days.rb', line 5

def name
  @name
end

#rangeObject (readonly)

Returns the value of attribute range.



5
6
7
# File 'lib/chinese/holidays/days.rb', line 5

def range
  @range
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/chinese/holidays/days.rb', line 5

def type
  @type
end

Instance Method Details

#daysObject



21
22
23
24
25
26
27
# File 'lib/chinese/holidays/days.rb', line 21

def days
  if @range.size == 1
    [Date.strptime(@range[0], '%F')]
  elsif @range.size == 2
    (Date.strptime(@range[0], '%F')..Date.strptime(@range[1], '%F')).to_a
  end
end

#holiday?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/chinese/holidays/days.rb', line 13

def holiday?
  @type == 'holiday'
end

#workingday?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/chinese/holidays/days.rb', line 17

def workingday?
  @type == 'workingday'
end