Class: Herodot::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/herodot/parser.rb

Constant Summary collapse

NO_SUCH_FILE =
Rainbow('Worklog missing.').red +
' Use `herodot init` to start tracking a git repository'\
' or `herodot help` to open the man page.'.freeze

Class Method Summary collapse

Class Method Details

.from_to_from_range(range) ⇒ Object



18
19
20
21
# File 'lib/herodot/parser.rb', line 18

def from_to_from_range(range)
  return [range, Time.now] unless range.respond_to?(:begin) && range.respond_to?(:end)
  [range.begin, range.end + 3600]
end

.parse(range, config) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/herodot/parser.rb', line 9

def parse(range, config)
  worklog = Worklog.new(config)
  from, to = from_to_from_range(range)
  parse_into_worklog(worklog, config.worklog_file, from, to)
  worklog
rescue Errno::ENOENT
  abort NO_SUCH_FILE
end