Class: ForestLiana::PieStatGetter
- Inherits:
-
Object
- Object
- ForestLiana::PieStatGetter
- Defined in:
- app/services/forest_liana/pie_stat_getter.rb
Instance Attribute Summary collapse
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(resource, params) ⇒ PieStatGetter
constructor
A new instance of PieStatGetter.
- #perform ⇒ Object
Constructor Details
#initialize(resource, params) ⇒ PieStatGetter
Returns a new instance of PieStatGetter.
5 6 7 8 |
# File 'app/services/forest_liana/pie_stat_getter.rb', line 5 def initialize(resource, params) @resource = resource @params = params end |
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
3 4 5 |
# File 'app/services/forest_liana/pie_stat_getter.rb', line 3 def record @record end |
Instance Method Details
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/services/forest_liana/pie_stat_getter.rb', line 10 def perform if @params[:group_by_field] value = @resource @params[:filters].try(:each) do |filter| operator, filter_value = OperatorValueParser.parse(filter[:value]) value = OperatorValueParser.add_where(value, filter[:field], operator, filter_value) end value = value.group(@params[:group_by_field]) .send(@params[:aggregate].downcase, @params[:aggregate_field]) .map do |k, v| { key: k, value: v } end @record = Model::Stat.new(value: value) end end |