Class: MyChart::XYZ

Inherits:
Object
  • Object
show all
Defined in:
lib/my_chart/xyz.rb

Instance Method Summary collapse

Constructor Details

#initialize(objs_2d_hash) ⇒ XYZ



3
4
5
# File 'lib/my_chart/xyz.rb', line 3

def initialize objs_2d_hash
  @objs_2d_hash = objs_2d_hash
end

Instance Method Details

#==(obj) ⇒ Object



25
26
27
# File 'lib/my_chart/xyz.rb', line 25

def == obj
  obj.kind_of? XYZ and value == obj.value
end

#datasetsObject



15
16
17
18
19
20
21
22
23
# 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

#labelsObject



11
12
13
# File 'lib/my_chart/xyz.rb', line 11

def labels
  value.keys
end

#valueObject



7
8
9
# File 'lib/my_chart/xyz.rb', line 7

def value
  @objs_2d_hash
end