class Trebbiatrice::Trebbia

Attributes

project[RW]
working_on[RW]

Public Class Methods

invoke!(*input) click to toggle source
# 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
new(login_data) click to toggle source
# File lib/trebbiatrice/trebbia.rb, line 15
def initialize(login_data)
  @harvest  = Harvest.new(login_data)
  @entry    = nil
  @tracking = false
end

Public Instance Methods

active_projects() click to toggle source
# 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) click to toggle source
# File lib/trebbiatrice/trebbia.rb, line 29
def get_task(name)
  @project.tasks.select { |t| t.name == name }.last
end
stop_tracking!() click to toggle source
# 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 = '') click to toggle source
# 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?() click to toggle source
# File lib/trebbiatrice/trebbia.rb, line 50
def tracking?
  !!@tracking
end

Private Instance Methods

today() click to toggle source
# File lib/trebbiatrice/trebbia.rb, line 71
def today
  Time.now.strftime('%Y/%m/%d')
end