Class: Graph::Bar

Inherits:
Object
  • Object
show all
Defined in:
lib/graph/bar.rb

Overview

This class allows the display of data arrays in bar graph format

Instance Method Summary collapse

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 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