class HistogramHelper
Attributes
data[R]
padding[R]
Public Class Methods
new(my_hash = {}, axis = 1)
click to toggle source
# File lib/graph-ruby.rb, line 100 def initialize(my_hash = {}, axis = 1) @data = my_hash @axis = axis @padding = calculate_padding end
Public Instance Methods
calculate_axis()
click to toggle source
# File lib/graph-ruby.rb, line 107 def calculate_axis if (@axis >0) @data.each {|key, value| @data[key] = value/@axis} end end
calculate_padding()
click to toggle source
# File lib/graph-ruby.rb, line 131 def calculate_padding longest_key_length = 0 @data.each do |key, value| longest_key_length = key.length if key.length > longest_key_length end return longest_key_length + 3 end
calculate_sum()
click to toggle source
# File lib/graph-ruby.rb, line 121 def calculate_sum sum = 0 @data.each do |key, value| sum += value end return sum end
convert_to_percentages()
click to toggle source
# File lib/graph-ruby.rb, line 113 def convert_to_percentages sum = calculate_sum @data.each do |key, value| @data[key] = ((value.to_f)/(sum.to_f)*100).to_i end end