Class: Clacky::RichUI::RichWorkPanel

Inherits:
Object
  • Object
show all
Includes:
Components::BaseComponent
Defined in:
lib/clacky/rich_ui/components/sidebar_panels.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Components::BaseComponent

#colored, #muted, #status_marker, #theme, #truncate

Constructor Details

#initializeRichWorkPanel

Returns a new instance of RichWorkPanel.



13
14
15
16
17
18
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 13

def initialize
  @plan = ""
  @activities = []
  @tasks = 0
  @cost = 0.0
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



11
12
13
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 11

def height
  @height
end

#widthObject

Returns the value of attribute width.



11
12
13
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 11

def width
  @width
end

Instance Method Details

#renderObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 33

def render
  lines = []
  lines << @plan unless @plan.empty?
  unless @activities.empty?
    lines << "" unless lines.empty?
    @activities.each do |a|
      marker = status_marker(a[:status] || :pending)
      lines << "#{marker} #{a[:label]}"
    end
  end
  lines << "" unless lines.empty?
  lines << muted("#{@tasks} tasks ยท $#{@cost.round(4)}")
  lines.join("\n")
end

#update_activities(activities) ⇒ Object



24
25
26
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 24

def update_activities(activities)
  @activities = Array(activities).last(8)
end

#update_plan(text) ⇒ Object



20
21
22
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 20

def update_plan(text)
  @plan = text.to_s
end

#update_stats(tasks, cost) ⇒ Object



28
29
30
31
# File 'lib/clacky/rich_ui/components/sidebar_panels.rb', line 28

def update_stats(tasks, cost)
  @tasks = tasks.to_i
  @cost = cost.to_f
end