Class: Ptimelog::Timelog
- Inherits:
-
Object
- Object
- Ptimelog::Timelog
- Includes:
- Singleton
- Defined in:
- lib/ptimelog/timelog.rb
Overview
Load and tokenize the data from gtimelog
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.load ⇒ Object
11 12 13 |
# File 'lib/ptimelog/timelog.rb', line 11 def load instance.load end |
.timelog_txt ⇒ Object
15 16 17 |
# File 'lib/ptimelog/timelog.rb', line 15 def timelog_txt Pathname.new(Configuration.instance[:timelog]). end |
Instance Method Details
#load ⇒ Object
20 21 22 |
# File 'lib/ptimelog/timelog.rb', line 20 def load @load ||= parse(read) end |
#parse(data) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ptimelog/timelog.rb', line 32 def parse(data) data.split("\n") .map { |line| tokenize(line) } .group_by { |match| match && match[:date] } .to_a end |
#read ⇒ Object
28 29 30 |
# File 'lib/ptimelog/timelog.rb', line 28 def read timelog_txt.read end |
#timelog_txt ⇒ Object
24 25 26 |
# File 'lib/ptimelog/timelog.rb', line 24 def timelog_txt self.class.timelog_txt end |
#tokenize(line) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ptimelog/timelog.rb', line 39 def tokenize(line) re_date = /(?<date>\d{4}-\d{2}-\d{2})/ re_time = /(?<time>\d{2}:\d{2})/ re_tick = /(?:(?<ticket>.*?): )/ re_desc = /(?<description>.*?)/ = /(?: -- (?<tags>.*)?)/ regexp = /^#{re_date} #{re_time}: #{re_tick}?#{re_desc}#{re_tags}?$/ line.match(regexp) end |