Class: Graph::Bar
- Inherits:
-
Object
- Object
- Graph::Bar
- Defined in:
- lib/graph/bar.rb
Overview
This class allows the display of data arrays in bar graph format
Instance Method Summary collapse
-
#data(data = nil) ⇒ Object
Get or Set the data array.
-
#initialize(data = nil) ⇒ Bar
constructor
Allows optionally setting the initial dataset as a parameter.
-
#print ⇒ Object
Print the bar graph to stdout.
Constructor Details
#initialize(data = nil) ⇒ Bar
Allows optionally setting the initial dataset as a parameter
12 13 14 |
# File 'lib/graph/bar.rb', line 12 def initialize(data = nil) @data = data end |
Instance Method Details
#data(data = nil) ⇒ Object
Get or Set the data array
19 20 21 22 |
# File 'lib/graph/bar.rb', line 19 def data(data = nil) @data = data unless data.nil? @data end |
#print ⇒ Object
Print the bar graph to stdout
27 28 29 30 31 |
# File 'lib/graph/bar.rb', line 27 def print @data.each_with_index do |count, index| printf "%02d|%s\n", index, ('#' * count) end end |