Class: Trebbiatrice::Trebbia

Inherits:
Object
  • Object
show all
Defined in:
lib/trebbiatrice/trebbia.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login_data) ⇒ Trebbia

Returns a new instance of Trebbia.



15
16
17
18
19
# File 'lib/trebbiatrice/trebbia.rb', line 15

def initialize()
  @harvest  = Harvest.new()
  @entry    = nil
  @tracking = false
end

Instance Attribute Details

#projectObject

Returns the value of attribute project.



13
14
15
# File 'lib/trebbiatrice/trebbia.rb', line 13

def project
  @project
end

#working_onObject

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_projectsObject



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

Returns:

  • (Boolean)


50
51
52
# File 'lib/trebbiatrice/trebbia.rb', line 50

def tracking?
  !!@tracking
end