Class: ActivePeriod::Holiday
- Inherits:
-
Day
show all
- Defined in:
- lib/active_period/holiday.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Day
#holiday?
#year
#quarter
#month
#week
#to_i
Methods inherited from Period
#&, #==, #===, #beginless?, #boundless?, #calculated_begin, #calculated_end, #endless?, #infinite?, #to_i, #|
#holidays
Methods included from Comparable
#<=>, #clamp_on, #include?
Methods inherited from Range
#to_period
Constructor Details
#initialize(date:, name:, regions:, options:) ⇒ Type
Returns ActivePeriod::Holiday.
23
24
25
26
27
28
29
30
|
# File 'lib/active_period/holiday.rb', line 23
def initialize(date: , name:, regions: , options: )
raise I18n.t(:gem_require, scope: %i[active_period holiday_period]) unless Object.const_defined?('Holidays')
super(date)
@name = name
@regions = regions
@options = options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
7
8
9
|
# File 'lib/active_period/holiday.rb', line 7
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
15
16
17
|
# File 'lib/active_period/holiday.rb', line 15
def options
@options
end
|
#regions ⇒ Object
Returns the value of attribute regions.
11
12
13
|
# File 'lib/active_period/holiday.rb', line 11
def regions
@regions
end
|
Class Method Details
._period ⇒ Object
45
46
47
|
# File 'lib/active_period/holiday.rb', line 45
def self._period
'day'
end
|
Instance Method Details
#+(duration) ⇒ self
Shift a period to the past acording to her ending point
57
58
59
|
# File 'lib/active_period/holiday.rb', line 57
def +(duration)
raise NotImplementedError
end
|
#-(duration) ⇒ self
Shift a period to the past acording to her starting point
51
52
53
|
# File 'lib/active_period/holiday.rb', line 51
def -(duration)
raise NotImplementedError
end
|
#_period ⇒ Object
41
42
43
|
# File 'lib/active_period/holiday.rb', line 41
def _period
self.class._period
end
|
#i18n(&block) ⇒ Object
Also known as:
inspect
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/active_period/holiday.rb', line 69
def i18n(&block)
return yield(self) if block.present?
I18n.t(:default_format,
scope: i18n_scope,
name: name,
wday: I18n.l(from, format: '%A').capitalize,
day: from.day,
month: I18n.l(from, format: '%B').capitalize,
year: from.year)
end
|
#i18n_scope ⇒ Object
82
83
84
|
# File 'lib/active_period/holiday.rb', line 82
def i18n_scope
[:active_period, :holiday_period]
end
|
#next ⇒ Object
Also known as:
succ
32
33
34
|
# File 'lib/active_period/holiday.rb', line 32
def next
Period.new(beginning+1.day..).holidays(options).first
end
|
#prev ⇒ Object
37
38
39
|
# File 'lib/active_period/holiday.rb', line 37
def prev
Period.new(...ending).holidays(options).last
end
|
#strftime(format) ⇒ Object
61
62
63
|
# File 'lib/active_period/holiday.rb', line 61
def strftime(format)
from.strftime(format)
end
|
#to_s(format: '%d/%m/%Y') ⇒ Object
65
66
67
|
# File 'lib/active_period/holiday.rb', line 65
def to_s(format: '%d/%m/%Y')
strftime(format)
end
|