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
- #load ⇒ Object
- #parse(data) ⇒ Object
- #previous_entry ⇒ Object
- #read ⇒ Object
- #timelog_txt ⇒ Object
- #tokenize(line) ⇒ Object
Class Method Details
.load ⇒ Object
11 12 13 |
# File 'lib/ptimelog/timelog.rb', line 11 def load instance.load end |
.previous_entry ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/ptimelog/timelog.rb', line 19 def previous_entry lines = timelog_txt.readlines.last(2) last_line = lines.map(&:chomp).delete_if(&:empty?).last last_entry = instance.tokenize(last_line) Entry.from_timelog(last_entry) 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
28 29 30 |
# File 'lib/ptimelog/timelog.rb', line 28 def load @load ||= parse(read) end |
#parse(data) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/ptimelog/timelog.rb', line 44 def parse(data) data.split("\n") .map { |line| tokenize(line) } .group_by { |match| match && match[:date] } .to_a end |
#previous_entry ⇒ Object
36 37 38 |
# File 'lib/ptimelog/timelog.rb', line 36 def previous_entry self.class.previous_entry end |
#read ⇒ Object
40 41 42 |
# File 'lib/ptimelog/timelog.rb', line 40 def read timelog_txt.read end |
#timelog_txt ⇒ Object
32 33 34 |
# File 'lib/ptimelog/timelog.rb', line 32 def timelog_txt self.class.timelog_txt end |
#tokenize(line) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ptimelog/timelog.rb', line 51 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}#{}?$/ line.match(regexp) end |