class ToBarGraph::BarGraph

Attributes

buckets[R]

Public Class Methods

new(array) click to toggle source
# File lib/bar_graph.rb, line 8
def initialize(array)
  bucketizer  = Bucketizer.new(array)
  @buckets    = bucketizer.create_buckets
end

Public Instance Methods

[](key) click to toggle source
# File lib/bar_graph.rb, line 20
def [](key)
  return @buckets[key]
end
bucket_contents_length() click to toggle source
# File lib/bar_graph.rb, line 36
def bucket_contents_length
  @buckets.reduce(0) { |sum, x| sum + x[1] }
end
each() { |b| ... } click to toggle source
# File lib/bar_graph.rb, line 14
def each(&block)
  @buckets.each do |b|
    yield b
  end
end
inspect() click to toggle source
# File lib/bar_graph.rb, line 48
def inspect
  return "class: #{self.class} object_id: #{self.object_id}"
end
length() click to toggle source
# File lib/bar_graph.rb, line 24
def length
  return @buckets.length
end
longest_category_name() click to toggle source
# File lib/bar_graph.rb, line 40
def longest_category_name
  longest = ''

  @buckets.each { |h| longest = h[0] if (h[0].length > longest.length) }

  return (longest == '') ? 0 : longest
end
max_value() click to toggle source
# File lib/bar_graph.rb, line 32
def max_value
  return (@buckets.max_by { |k, v| @buckets[k] })[1]
end
min_value() click to toggle source
# File lib/bar_graph.rb, line 28
def min_value
  return @buckets.min_by { |k, v| @buckets[k] }[1]
end