Class: ActivePeriod::FreePeriod
- Defined in:
- lib/active_period/free_period.rb
Instance Method Summary collapse
-
#+(duration) ⇒ self
Shift a period to the future.
-
#-(duration) ⇒ self
Shift a period to the past.
- #bounding_format ⇒ Object
- #ending ⇒ Object
-
#i18n {|from, to, exclude_end?| ... } ⇒ Object
If no block given, it's an alias to to_s For a block {|from,to| … }.
-
#strftime(format) ⇒ String
Formated string.
-
#to_i ⇒ ActiveSupport::Duration
Don't return an Integer.
-
#to_s(format: '%d %B %Y') ⇒ String
Formated string.
Methods included from HasMany::Years
Methods included from HasMany::Quarters
Methods included from HasMany::Months
Methods included from HasMany::Weeks
Methods included from HasMany::Days
Methods inherited from Period
#&, #==, #===, #beginless?, #boundless?, #calculated_begin, #calculated_end, #endless?, #infinite?, #initialize, #next, #prev, #|
Methods included from HasMany::Holidays
Methods included from Comparable
Methods inherited from Range
Constructor Details
This class inherits a constructor from ActivePeriod::Period
Instance Method Details
#+(duration) ⇒ self
Shift a period to the future
34 35 36 |
# File 'lib/active_period/free_period.rb', line 34 def +(duration) self.class.new((from + duration)..(to + duration)) end |
#-(duration) ⇒ self
Shift a period to the past
27 28 29 |
# File 'lib/active_period/free_period.rb', line 27 def -(duration) self.class.new((from - duration)..(to - duration)) end |
#bounding_format ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/active_period/free_period.rb', line 54 def bounding_format if boundless? :boundless_format elsif beginless? :beginless_format elsif endless? :endless_format else :default_format end end |
#ending ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/active_period/free_period.rb', line 66 def ending if exclude_end? :excluded else :included end end |
#i18n {|from, to, exclude_end?| ... } ⇒ Object
If no block given, it's an alias to to_s For a block {|from,to| … }
79 80 81 82 83 |
# File 'lib/active_period/free_period.rb', line 79 def i18n(&block) return yield(from, to, exclude_end?) if block.present? to_s end |
#strftime(format) ⇒ String
Returns Formated string.
40 41 42 |
# File 'lib/active_period/free_period.rb', line 40 def strftime(format) to_s(format: format) end |
#to_i ⇒ ActiveSupport::Duration
Don't return an Integer. ActiveSupport::Duration is a better numeric representation a in time manipulation context
19 20 21 22 |
# File 'lib/active_period/free_period.rb', line 19 def to_i return Float::INFINITY if infinite? days.count.days end |
#to_s(format: '%d %B %Y') ⇒ String
Returns Formated string.
46 47 48 49 50 51 52 |
# File 'lib/active_period/free_period.rb', line 46 def to_s(format: '%d %B %Y') I18n.t(bounding_format, scope: %i[active_period free_period], from: I18n.l(self.begin, format: format, default: nil), to: I18n.l(self.end, format: format, default: nil), ending: I18n.t(ending, scope: %i[active_period])) end |