Class: GraphDrawer::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/graph_drawer/data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, value) ⇒ Data



9
10
11
12
13
# File 'lib/graph_drawer/data.rb', line 9

def initialize(item, value)
  @item = item
  @value = value
  @level = nil
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



5
6
7
# File 'lib/graph_drawer/data.rb', line 5

def item
  @item
end

#levelObject

Returns the value of attribute level.



7
8
9
# File 'lib/graph_drawer/data.rb', line 7

def level
  @level
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/graph_drawer/data.rb', line 6

def value
  @value
end

Instance Method Details

#to_sObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/graph_drawer/data.rb', line 15

def to_s
  color =
    case @level
    when 1
      :green
    when 2
      :cyan
    when 3
      :blue
    end

  if @value.zero?
    draw_str = "#{@item}|"
  else
    bar = ' ' * (@value - 1)
    data_label = @value.to_s.color(:black)
    draw_str = "#{@item}|#{(bar + data_label).bg_color(color)}"
  end

  draw_str
end