Class: Trebbiatrice::Trebbia
- Inherits:
-
Object
- Object
- Trebbiatrice::Trebbia
- Defined in:
- lib/trebbiatrice/trebbia.rb
Instance Attribute Summary collapse
-
#project ⇒ Object
Returns the value of attribute project.
-
#working_on ⇒ Object
Returns the value of attribute working_on.
Class Method Summary collapse
Instance Method Summary collapse
- #active_projects ⇒ Object
- #get_task(name) ⇒ Object
-
#initialize(login_data) ⇒ Trebbia
constructor
A new instance of Trebbia.
- #stop_tracking! ⇒ Object
- #track!(task = 'Development', notes = '') ⇒ Object
- #tracking? ⇒ Boolean
Constructor Details
Instance Attribute Details
#project ⇒ Object
Returns the value of attribute project.
13 14 15 |
# File 'lib/trebbiatrice/trebbia.rb', line 13 def project @project end |
#working_on ⇒ Object
Returns the value of attribute working_on.
13 14 15 |
# File 'lib/trebbiatrice/trebbia.rb', line 13 def working_on @working_on end |
Class Method Details
.invoke!(*input) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/trebbiatrice/trebbia.rb', line 55 def invoke!(*input) stdin, stdout, stderr = Open3.popen3(*input) response = unless stderr.read.chomp.strip.empty? { status: 'failure', contents: stderr } else { status: 'success', contents: stdout } end response[:contents] = response[:contents].read.each_line.map(&:chomp) response end |
Instance Method Details
#active_projects ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/trebbiatrice/trebbia.rb', line 21 def active_projects @harvest.projects.select do |project| project_name = project[:name].downcase matches = @working_on.split('/').select { |part| project_name.include?(part.downcase) } matches.reject(&:empty?).any? end end |
#get_task(name) ⇒ Object
29 30 31 |
# File 'lib/trebbiatrice/trebbia.rb', line 29 def get_task(name) @project.tasks.select { |t| t.name == name }.last end |
#stop_tracking! ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/trebbiatrice/trebbia.rb', line 42 def stop_tracking! if @entry && tracking? @tracking = false @harvest.toggle!(@entry[:id]) @entry = nil end end |
#track!(task = 'Development', notes = '') ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/trebbiatrice/trebbia.rb', line 33 def track!(task = 'Development', notes = '') return if tracking? task_id = get_task(task)[:id] @entry = @harvest.new_entry! notes: notes, hours: 0, spent_at: today, project_id: @project[:id], task_id: task_id @tracking = true end |
#tracking? ⇒ Boolean
50 51 52 |
# File 'lib/trebbiatrice/trebbia.rb', line 50 def tracking? !!@tracking end |