Module: TimeExt::Support

Included in:
Time
Defined in:
lib/time_ext/support.rb

Overview

Provides helper methods used by TimeExt::Calculations for backwards compatibility with ActiveSupport, and method chaining helpers for TimeExt::Iterations.

Instance Method Summary collapse

Instance Method Details

#add_to_chain(method, *args, &block) ⇒ Object



13
14
15
16
# File 'lib/time_ext/support.rb', line 13

def add_to_chain(method, *args, &block)
  @method_chain ||= []
  @method_chain << [method.to_sym, args, block]
end

#call_chain(custom_block = nil, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/time_ext/support.rb', line 18

def call_chain(custom_block = nil, &block)
  method, args, iblock = @method_chain.pop
  return nil if method.nil?
  iblock = custom_block if !custom_block.nil?
  method, args, iblock = yield(method, args, iblock) if block_given?
  self.send(method, *args, &iblock)
end

#common_year_days_in_monthObject



9
10
11
# File 'lib/time_ext/support.rb', line 9

def common_year_days_in_month
  defined?(COMMON_YEAR_DAYS_IN_MONTH) ? COMMON_YEAR_DAYS_IN_MONTH : [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
end

#days_into_weekObject



5
6
7
# File 'lib/time_ext/support.rb', line 5

def days_into_week
  defined?(DAYS_INTO_WEEK) ? DAYS_INTO_WEEK : { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6 }
end