lib/timespan.rb in timespan-0.2.7 vs lib/timespan.rb in timespan-0.2.8

- old
+ new

@@ -23,12 +23,12 @@ attr_reader :start_time, :end_time alias_method :start_date, :start_time alias_method :end_date, :end_time - START_KEYS = [:start, :from] - END_KEYS = [:to, :end] + START_KEYS = [:start, :from, :start_date] + END_KEYS = [:to, :end, :end_date] DURATION_KEYS = [:duration, :lasting] ALL_KEYS = START_KEYS + END_KEYS + DURATION_KEYS def initialize options = {} @@ -100,29 +100,29 @@ keys.select {|key| options[key] }.first end # uses init_options to configure def configure! options = {} - from = options[first_from START_KEYS, options] - to = options[first_from END_KEYS, options] - dur = options[first_from DURATION_KEYS, options] + from = options[first_from(START_KEYS, options)] + to = options[first_from(END_KEYS, options)] + dur = options[first_from(DURATION_KEYS, options)] self.duration = dur if dur self.start_time = from if from self.end_time = to if to - default_from_now! unless start_time || end_time - + default_from_now! calculate_miss! rescue ArgumentError => e raise TimeParseError, e.message rescue Exception => e calculate_miss! validate! end def default_from_now! - self.start_time = Time.now + self.start_time = Time.now unless start_time || (end_time && duration) + self.end_time = Time.now unless end_time || (start_time && duration) end def validate! raise ArgumentError, "#{valid_requirement}, was: #{init_options.inspect} resulting in state: #{current_config}" unless valid? end \ No newline at end of file