Class: Chart
Instance Method Summary collapse
- #<=>(other_value) ⇒ Object
- #cumulative ⇒ Object
- #each(&block) ⇒ Object
- #group_by ⇒ Object
-
#initialize(arry_times) ⇒ Chart
constructor
A new instance of Chart.
- #legend ⇒ Object
- #percent_of ⇒ Object
- #to_h ⇒ Object
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 |
#cumulative ⇒ Object
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_by ⇒ Object
23 24 25 |
# File 'lib/montecasting/chart.rb', line 23 def group_by to_h.to_chart(&:to_i) end |
#legend ⇒ Object
19 20 21 |
# File 'lib/montecasting/chart.rb', line 19 def legend to_h.to_chart() end |
#percent_of ⇒ Object
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_h ⇒ Object
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 |