class Enumdate::DateFrame::Base

DateFrame: yearly, monthly, weekly, and daily

Public Class Methods

new(first_date, interval = 1, wkst = 1) click to toggle source
# File lib/enumdate/date_frame.rb, line 77
def initialize(first_date, interval = 1, wkst = 1)
  @first_date, @interval, @wkst = first_date, interval, wkst
  rewind
end

Public Instance Methods

each() { |current_frame_date| ... } click to toggle source
# File lib/enumdate/date_frame.rb, line 82
def each
  return enum_for(:each) unless block_given?

  loop do
    yield @current_frame_date
    @current_frame_date = next_frame_start(@current_frame_date)
  end
end
forward_to(date) click to toggle source

Go forward to the frame in which DATE is involved

# File lib/enumdate/date_frame.rb, line 98
def forward_to(date)
  rewind # reset @current_frame_date
  frames = frames_between(@current_frame_date, date)
  cycles = (frames + (@interval - 1)) / @interval
  @current_frame_date = next_frame_start(@current_frame_date, cycles) if cycles.positive?
  self
end
rewind() click to toggle source

Imprement rewind for Enumrator class

# File lib/enumdate/date_frame.rb, line 92
def rewind
  @current_frame_date = beginning_of_frame(@first_date)
  self
end

Private Instance Methods

beginning_of_frame(date) click to toggle source
# File lib/enumdate/date_frame.rb, line 112
def beginning_of_frame(date)
  raise NotImplementedError
end
frames_between(date1, date2) click to toggle source
# File lib/enumdate/date_frame.rb, line 116
def frames_between(date1, date2)
  raise NotImplementedError
end
next_frame_start(current_frame_date, cycles = 1) click to toggle source
# File lib/enumdate/date_frame.rb, line 108
def next_frame_start(current_frame_date, cycles = 1)
  raise NotImplementedError
end