Class: ActivePeriod::Quarter

Inherits:
StandardPeriod show all
Includes:
BelongsTo::Year, HasMany::Days, HasMany::Months, HasMany::Weeks
Defined in:
lib/active_period/quarter.rb

Overview

Note:

One of the StandardPeriod defined in the gem

Author:

  • Lucas Billaudot <billau_l@modulotech.fr>

Instance Method Summary collapse

Methods included from BelongsTo::Year

#year

Methods included from HasMany::Months

#months

Methods included from HasMany::Weeks

#weeks

Methods included from HasMany::Days

#days

Methods inherited from StandardPeriod

#+, #-, #_period, _period, #i18n_scope, #initialize, #next, #prev, #to_i

Methods inherited from Period

#&, #+, #-, #==, #===, #beginless?, #boundless?, #calculated_begin, #calculated_end, #endless?, #infinite?, #initialize, #next, #prev, #to_i, #|

Methods included from HasMany::Holidays

#holidays

Methods included from Comparable

#<=>, #include?

Methods inherited from Range

#to_period

Constructor Details

This class inherits a constructor from ActivePeriod::StandardPeriod

Instance Method Details

#i18n(&block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/active_period/quarter.rb', line 32

def i18n(&block)
  return yield(from, to) if block.present?

  I18n.t(:default_format,
         scope:       i18n_scope,
         quarter_nb:  quarter_nb,
         year:        from.year)
end

#quarter_nbObject



24
25
26
# File 'lib/active_period/quarter.rb', line 24

def quarter_nb
  @quarter_nb ||= (from.month / 3.0).ceil
end

#strftime(format) ⇒ Object



19
20
21
22
# File 'lib/active_period/quarter.rb', line 19

def strftime(format)
  format = format.gsub(':quarter', quarter_nb.to_s)
  from.strftime(format)
end

#to_sObject



28
29
30
# File 'lib/active_period/quarter.rb', line 28

def to_s
  i18n
end