module Periods::Modules::SingleDateInitialize::InstanceMethods

Public Class Methods

new(date) click to toggle source

Initialize a new period based on a single given date.

@example

period = <Class>.new(Date.new(2015,6,25))
period = <Class>.new('25.06.2015')
period = <Class>.new(<Class>.new('25.06.2015')
# File lib/periods/modules/single_date_initialize.rb, line 28
def initialize(date)
  if date.is_a?(self.class)
    init_with_dates(date.start_date, date.end_date)
  elsif date.is_a?(Date)
    init_with_date(date)
  elsif date.is_a?(String)
    init_with_date(Date.parse(date.to_s))
  elsif date.is_a?(Time)
    init_with_date(Date.parse(date.to_s))
  else
    raise ArgumentError, "#{self.class} cannot be initialized with #{date.class}"
  end
end

Protected Instance Methods

init_with_date(date) click to toggle source
# File lib/periods/modules/single_date_initialize.rb, line 43
def init_with_date(date)
  raise "Please implement."
end

Private Instance Methods

init_with_dates(start_date, end_date) click to toggle source
# File lib/periods/modules/single_date_initialize.rb, line 48
def init_with_dates(start_date, end_date)
  @start_date = start_date
  @end_date = end_date
end