Module: Periods::Modules::SingleDateInitialize::InstanceMethods
- Defined in:
- lib/periods/modules/single_date_initialize.rb
Instance Method Summary collapse
- #init_with_date(date) ⇒ Object protected
-
#initialize(date) ⇒ Object
Initialize a new period based on a single given date.
Instance Method Details
#init_with_date(date) ⇒ Object (protected)
43 44 45 |
# File 'lib/periods/modules/single_date_initialize.rb', line 43 def init_with_date(date) raise "Please implement." end |
#initialize(date) ⇒ Object
Initialize a new period based on a single given date.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 |