Class: Chart

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/montecasting/chart.rb

Instance Method Summary collapse

Constructor Details

#initialize(arry_times) ⇒ Chart

Returns a new instance of Chart.



7
8
9
# File 'lib/montecasting/chart.rb', line 7

def initialize(arry_times)
  @elements = arry_times
end

Instance Method Details

#<=>(other_value) ⇒ Object



15
16
17
# File 'lib/montecasting/chart.rb', line 15

def <=>(other_value)
  self <=> other_value
end

#cumulativeObject



31
32
33
34
# File 'lib/montecasting/chart.rb', line 31

def cumulative
  to_h.keys.to_chart {|index| to_h.values.take(index).inject(0) {|acc, elem| acc + elem}.percent_of(count).ceil(0)}

end

#each(&block) ⇒ Object



11
12
13
# File 'lib/montecasting/chart.rb', line 11

def each(&block)
  @elements.each(&block)
end

#group_byObject



23
24
25
# File 'lib/montecasting/chart.rb', line 23

def group_by
  to_h.to_chart(&:to_i)
end

#legendObject



19
20
21
# File 'lib/montecasting/chart.rb', line 19

def legend
  to_h.to_chart()
end

#percent_ofObject



27
28
29
# File 'lib/montecasting/chart.rb', line 27

def percent_of
  to_h.to_chart {|value| value.percent_of(count).ceil(0)}
end

#to_hObject



36
37
38
# File 'lib/montecasting/chart.rb', line 36

def to_h
  uniq.sort.to_h {|s| [s, count{|elem| elem.equal? s}]}
end