Class: RCharts::GraphHelper::Graph::Calculator
- Inherits:
-
Object
- Object
- RCharts::GraphHelper::Graph::Calculator
- Defined in:
- app/helpers/rcharts/graph_helper/graph/calculator.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(values = {}) ⇒ Calculator
constructor
A new instance of Calculator.
- #signed(sign = nil) ⇒ Object
- #stacked(exclude_current: false) ⇒ Object
- #sum_complete ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(values = {}) ⇒ Calculator
Returns a new instance of Calculator.
9 10 11 12 13 |
# File 'app/helpers/rcharts/graph_helper/graph/calculator.rb', line 9 def initialize(values = {}) @values = values @chain = [] @selections = {} end |
Instance Method Details
#signed(sign = nil) ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/helpers/rcharts/graph_helper/graph/calculator.rb', line 25 def signed(sign = nil) return self unless sign apply sign do values_for_predicate sign == :positive ? :positive? : :negative? end end |
#stacked(exclude_current: false) ⇒ Object
33 34 35 36 37 |
# File 'app/helpers/rcharts/graph_helper/graph/calculator.rb', line 33 def stacked(exclude_current: false) apply :stacked, exclude_current do collect_sum inclusive: !exclude_current end end |
#sum_complete ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/rcharts/graph_helper/graph/calculator.rb', line 15 def sum_complete values.transform_values do |value| case value when Hash then value.values.any?(nil) ? nil : value.values.sum when Array then value.any?(nil) ? nil : value.sum else value end end end |
#to_h ⇒ Object
39 40 41 42 43 44 45 |
# File 'app/helpers/rcharts/graph_helper/graph/calculator.rb', line 39 def to_h keys.index_with do |key| next values if key.nil? values.transform_values { it[key] } end end |