Class: TTrack
- Inherits:
-
Object
- Object
- TTrack
- Defined in:
- lib/ttrack.rb
Overview
TTrack class
Class that handles communication between CLI and data storage
Defined Under Namespace
Classes: DataStore
Instance Method Summary collapse
-
#commands ⇒ Object
List of available public methods.
-
#init ⇒ Object
Cleanup the database.
-
#initialize(datastore) ⇒ TTrack
constructor
At each call we need to declare the datastore.
-
#report(issuename = nil) ⇒ Object
Get a report for the given issue name If no issue is give, get a report for everything.
-
#set_tstart!(issueid, timestamp) ⇒ Object
Overwrite tstart for given issue with given timestamp.
-
#set_tstop!(issueid, timestamp) ⇒ Object
Override tstop for given issue.
-
#start(issuename, notes = '') ⇒ Object
Start tracking an issue, stop the current one if running Return boolean to indicate if the action was succesfull or not.
-
#status(issuename = nil) ⇒ Object
Get current running task status if no issuename given Otherwise get total duration for named task (i.e. for any matching time entry).
-
#stop ⇒ Object
Stop the current running task Return info about the stopped running task, false if it was not tracking.
Constructor Details
Instance Method Details
#commands ⇒ Object
List of available public methods
117 118 119 |
# File 'lib/ttrack.rb', line 117 def commands [:start, :stop, :status, :init, :report, :begin, :end] end |
#init ⇒ Object
Cleanup the database
112 113 114 |
# File 'lib/ttrack.rb', line 112 def init @db.cleanup end |
#report(issuename = nil) ⇒ Object
Get a report for the given issue name If no issue is give, get a report for everything
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ttrack.rb', line 60 def report issuename=nil result = Array.new if issuename.nil? or issuename.empty? r = @db.gettimesheet r.each do |line| result << { :task => line[0], :name => line[1], :tstart => line[2], :tstop => line[3], :synced => line[4], :notes => line[5], :elapsed => getissueduration(line[0]) } end else r = @db.getissuesbyname issuename r.each do |line| result << { :task => line[0], :tstart => line[1], :tstop => line[2], :synced => line[3], :notes => line[4], :elapsed => getissueduration(line[0]) } end end result.empty? ? nil : result end |
#set_tstart!(issueid, timestamp) ⇒ Object
Overwrite tstart for given issue with given timestamp
93 94 95 96 97 98 99 100 101 |
# File 'lib/ttrack.rb', line 93 def set_tstart! issueid, if validateissueid(issueid) t = () @db.settstart(issueid, t) true else false end end |
#set_tstop!(issueid, timestamp) ⇒ Object
Override tstop for given issue
104 105 106 107 108 109 |
# File 'lib/ttrack.rb', line 104 def set_tstop! issueid, if validateissueid issueid t = @db.settstop issueid, t end end |
#start(issuename, notes = '') ⇒ Object
Start tracking an issue, stop the current one if running Return boolean to indicate if the action was succesfull or not
16 17 18 19 20 21 22 23 24 |
# File 'lib/ttrack.rb', line 16 def start issuename, notes='' unless issuename.nil? or issuename.empty? stopresult = stop if @db.getcurrent @db.startnew issuename, notes [true, stopresult] else false end end |
#status(issuename = nil) ⇒ Object
Get current running task status if no issuename given Otherwise get total duration for named task (i.e. for any matching time entry)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ttrack.rb', line 43 def status issuename=nil if issuename.nil? status = @db.getstatus if status delta = Time.now - gettstart(@db.getcurrent) {:task => status[1], :elapsed => delta} end else total = gettotalissueduration(issuename) unless total.nil? {:task => issuename, :elapsed => total} end end end |
#stop ⇒ Object
Stop the current running task Return info about the stopped running task, false if it was not tracking
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ttrack.rb', line 28 def stop result = @db.stoprunning if result and result != [] { :name => @db.getnamebyissueid(result)[0][0], :id => result, :elapsed => getissueduration(result) } else false end end |