Class: ActivePeriod::StandardPeriod
- Defined in:
- lib/active_period/standard_period.rb
Class Method Summary collapse
-
._period ⇒ String
Get the name of the standard period.
Instance Method Summary collapse
-
#+(duration) ⇒ self
Shift a period to the past acording to her ending point.
-
#-(duration) ⇒ self
Shift a period to the past acording to her starting point.
- #_period ⇒ Object
- #i18n_scope ⇒ Object
-
#initialize(object) ⇒ StandardPeriod
constructor
A new instance of StandardPeriod.
- #next ⇒ Object (also: #succ)
- #prev ⇒ Object
-
#to_i ⇒ ActiveSupport::Duration
Don’t realy return an Integer.
Methods inherited from Period
#&, #==, #===, #beginless?, #boundless?, #calculated_begin, #calculated_end, #endless?, #i18n, #infinite?, #strftime, #to_s, #|
Methods included from HasMany::Holidays
Methods included from Comparable
Methods inherited from Range
Constructor Details
#initialize(object) ⇒ StandardPeriod
Returns a new instance of StandardPeriod.
4 5 6 7 8 |
# File 'lib/active_period/standard_period.rb', line 4 def initialize(object) raise I18n.t(:base_class_id_abstract, scope: %i[active_period standard_period]) if self.class == StandardPeriod time = time_parse(object, I18n.t(:date_is_invalid, scope: %i[active_period standard_period]) ) super(time.send("beginning_of_#{_period}")..time.send("end_of_#{_period}")) end |
Class Method Details
._period ⇒ String
Returns get the name of the standard period.
24 25 26 |
# File 'lib/active_period/standard_period.rb', line 24 def self._period name.split('::').last.downcase end |
Instance Method Details
#+(duration) ⇒ self
Shift a period to the past acording to her ending point
43 44 45 |
# File 'lib/active_period/standard_period.rb', line 43 def +(duration) self.class.new(to + duration) end |
#-(duration) ⇒ self
Shift a period to the past acording to her starting point
37 38 39 |
# File 'lib/active_period/standard_period.rb', line 37 def -(duration) self.class.new(from - duration) end |
#_period ⇒ Object
19 20 21 |
# File 'lib/active_period/standard_period.rb', line 19 def _period self.class._period end |
#i18n_scope ⇒ Object
47 48 49 |
# File 'lib/active_period/standard_period.rb', line 47 def i18n_scope [:active_period, :standard_period, _period] end |
#next ⇒ Object Also known as: succ
10 11 12 |
# File 'lib/active_period/standard_period.rb', line 10 def next self.class.new(from.send("next_#{_period}")) end |
#prev ⇒ Object
15 16 17 |
# File 'lib/active_period/standard_period.rb', line 15 def prev self.class.new(from.send("prev_#{_period}")) end |
#to_i ⇒ ActiveSupport::Duration
Don’t realy return an Integer. ActiveSupport::Duration is a better numeric representation a in time manipulation context
31 32 33 |
# File 'lib/active_period/standard_period.rb', line 31 def to_i 1.send(_period) end |