Class: InputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/worked/inputparser.rb

Class Method Summary collapse

Class Method Details

.parse(source, now = DateTime.now) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/worked/inputparser.rb', line 32

def self.parse(source, now = DateTime.now)

  from, to, total, activity = parse_input source

  from ||= time_in_seconds_from_day(now - total)
  to   ||= time_in_seconds_from_day(now)

  if from > to
    from -= 24.hours
  end

  midnight = DateTime.new(now.year, now.month, now.day)

  [midnight + from.seconds, midnight + to.seconds, activity]
end