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?

Methods included from BelongsTo::Year

#year

Methods included from BelongsTo::Quarter

#quarter

Methods included from BelongsTo::Month

#month

Methods included from BelongsTo::Week

#week

Methods inherited from StandardPeriod

#to_i

Methods inherited from Period

#==, #beginless?, #boundless?, #calculated_begin, #calculated_end, #endless?, #infinite?, #to_i

Methods included from ActivePeriod::HasMany::Holidays

#holidays

Methods included from Comparable

#<=>, #include?

Methods inherited from Range

#to_period

Constructor Details

#initialize(date:, name:, regions:, options:) ⇒ Type

Returns ActivePeriod::Holiday.

Parameters:

  • date (...)

    A valid param for Period.day(…)

  • name (String)

    The name of the Holiday

  • regions (<Symbol>)

    region where the Holiday occure

  • options (...)

    The array of options for Holidays.on

Raises:

  • RuntimeError if the gem “holidays” is not included



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

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/active_period/holiday.rb', line 7

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/active_period/holiday.rb', line 15

def options
  @options
end

#regionsObject (readonly)

Returns the value of attribute regions.



11
12
13
# File 'lib/active_period/holiday.rb', line 11

def regions
  @regions
end

Class Method Details

._periodObject



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

Returns:

  • (self)

    A new period of the same kind

Raises:

  • (NotImplementedError)


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

Returns:

  • (self)

    A new period of the same kind

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/active_period/holiday.rb', line 51

def -(duration)
  raise NotImplementedError
end

#_periodObject



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_scopeObject



82
83
84
# File 'lib/active_period/holiday.rb', line 82

def i18n_scope
  [:active_period, :holiday_period]
end

#nextObject 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

#prevObject



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