module Period

@author Lucas Billaudot <billau_l@modulotech.fr> @note This module define all period of time, who are include in the current period

@author Lucas Billaudot <billau_l@modulotech.fr> @note One of the StandardPeriod defined in the gem

Constants

VERSION

Public Class Methods

env_time() click to toggle source
# File lib/period.rb, line 21
def self.env_time
  (Time.zone || Time)
end
method_missing(method_name, *arguments, &block) click to toggle source
Calls superclass method
# File lib/period.rb, line 50
def method_missing(method_name, *arguments, &block)
  super unless method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/)
  last_next, count, klass = method_name.to_s.split('_')
  klass = klass.singularize

  case last_next
  when 'last'
    from = count.to_i.send(klass).ago.send("beginning_of_#{klass}")
    to = env_time.now
    to -= 1.send(klass) unless method_name.match?(/from_now$/)
    to = to.send("end_of_#{klass}")
  when 'next'
    from = env_time.now
    from += 1.send(klass) unless method_name.match?(/from_now$/)
    from = from.send("beginning_of_#{klass}")
    to = count.to_i.send(klass).from_now.send("end_of_#{klass}")
  end
  self.new(from..to)
end
new(range) click to toggle source
# File lib/period.rb, line 17
def self.new(range)
  Period::FreePeriod.new(range)
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/period.rb, line 70
def respond_to_missing?(method_name, include_private = false)
  method_name.match?(/(last|next)_\d+_(day|week|month|quarter|year)s?(_from_now)?/) || super
end