Module: Collimator::BarGraph
- Defined in:
- lib/collimator/bar_graph.rb
Class Method Summary collapse
- .clear_all ⇒ Object
- .clear_data ⇒ Object
- .data ⇒ Object
- .data=(data) ⇒ Object
- .options ⇒ Object
- .options=(options) ⇒ Object
- .plot(options = {}) ⇒ Object
Class Method Details
.clear_all ⇒ Object
8 9 10 11 12 |
# File 'lib/collimator/bar_graph.rb', line 8 def self.clear_all = "\u2588" @data = [] = {} end |
.clear_data ⇒ Object
14 15 16 |
# File 'lib/collimator/bar_graph.rb', line 14 def self.clear_data @data = [] end |
.data ⇒ Object
26 27 28 |
# File 'lib/collimator/bar_graph.rb', line 26 def self.data @data end |
.data=(data) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/collimator/bar_graph.rb', line 18 def self.data=(data) if data.is_a?(Array) @data = data elsif data.is_a?(Hash) @data << data end end |
.options ⇒ Object
30 31 32 |
# File 'lib/collimator/bar_graph.rb', line 30 def self. end |
.options=(options) ⇒ Object
34 35 36 |
# File 'lib/collimator/bar_graph.rb', line 34 def self.=() .merge!() end |
.plot(options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/collimator/bar_graph.rb', line 38 def self.plot( = {}) self. = header_width = max_header_length @data.each do |data| value = data[:value].to_i header = data[:name].ljust(header_width) = * value color = data.fetch(:color, 'cyan') begin = .send(color) rescue NoMethodError = end value = [:show_values] ? "#{value.to_s.rjust(3)}" : '' full_output = " #{header} #{value} #{bar}" puts full_output end end |