Class: TimeTrackr::YamlDatabase
- Defined in:
- lib/timetrackr/yaml.rb
Instance Method Summary collapse
- #clear(task) ⇒ Object
- #close ⇒ Object
- #current ⇒ Object
- #history(task, p_begin = nil, p_end = nil) ⇒ Object
-
#initialize(path) ⇒ YamlDatabase
constructor
A new instance of YamlDatabase.
- #rename(from, to) ⇒ Object
- #start(task, notes) ⇒ Object
- #stop(task) ⇒ Object
- #tasks ⇒ Object
Methods inherited from Database
Constructor Details
#initialize(path) ⇒ YamlDatabase
Returns a new instance of YamlDatabase.
16 17 18 19 20 21 22 23 |
# File 'lib/timetrackr/yaml.rb', line 16 def initialize(path) @log_path = path if !File.exist? @log_path @db = {:current => [], :tasks => {}} write_file end @db = YAML.load_file(@log_path) end |
Instance Method Details
#clear(task) ⇒ Object
65 66 67 68 |
# File 'lib/timetrackr/yaml.rb', line 65 def clear(task) @db[:current].delete(task) @db[:tasks].delete(task) end |
#close ⇒ Object
61 62 63 |
# File 'lib/timetrackr/yaml.rb', line 61 def close write_file end |
#current ⇒ Object
25 26 27 |
# File 'lib/timetrackr/yaml.rb', line 25 def current @db[:current] end |
#history(task, p_begin = nil, p_end = nil) ⇒ Object
48 49 50 51 52 |
# File 'lib/timetrackr/yaml.rb', line 48 def history(task, p_begin=nil, p_end=nil) @db[:tasks][task].sort{|x,y| x[:start] <=> y[:start]}.collect {|p| Period.new(task,p[:start],p[:stop],p[:notes]) } unless !@db[:tasks].include? task end |
#rename(from, to) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/timetrackr/yaml.rb', line 54 def rename(from, to) @db[:tasks][to] = @db[:tasks].delete(from) if @db[:current].delete(from) @db[:current].unshift(to) end end |
#start(task, notes) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/timetrackr/yaml.rb', line 33 def start(task, notes) @db[:tasks][task] = Array[] unless @db[:tasks][task] if !@db[:current].include?(task) @db[:current].unshift(task) @db[:tasks][task].push({:start => Time.now, :notes => notes}) end end |
#stop(task) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/timetrackr/yaml.rb', line 41 def stop(task) if @db[:current].include?(task) @db[:current].delete(task) @db[:tasks][task].last[:stop] = Time.now end end |
#tasks ⇒ Object
29 30 31 |
# File 'lib/timetrackr/yaml.rb', line 29 def tasks @db[:tasks].keys.compact.uniq || [] end |