class MyChart::XYZ

Public Class Methods

new(objs_2d_hash) click to toggle source
# File lib/my_chart/xyz.rb, line 3
def initialize objs_2d_hash
  @objs_2d_hash = objs_2d_hash
end

Public Instance Methods

==(obj) click to toggle source
# File lib/my_chart/xyz.rb, line 25
def == obj
  obj.kind_of? XYZ and value == obj.value
end
datasets() click to toggle source
# File lib/my_chart/xyz.rb, line 15
def datasets
  labels_in_datasets = keys_in_sub_hash value
  labels_in_datasets.map do |lb|
    {
      label: lb,
      data: value.map{ |k, sub_hash| sub_hash[lb] ? sub_hash[lb].count : 0}
    }
  end
end
labels() click to toggle source
# File lib/my_chart/xyz.rb, line 11
def labels
  value.keys
end
value() click to toggle source
# File lib/my_chart/xyz.rb, line 7
def value
  @objs_2d_hash
end

Private Instance Methods

keys_in_sub_hash(hash_2d) click to toggle source
# File lib/my_chart/xyz.rb, line 31
def keys_in_sub_hash hash_2d
  hash_2d.values.reduce([]) do |labels, hash|
    labels + hash.keys
  end.uniq.sort_by(&:to_s)
end