Sha256: 19e7fc96c8cb999b735b15c413c11498dd5a21d60339b0997273309a104683cc

Contents?: true

Size: 732 Bytes

Versions: 13

Compression:

Stored size: 732 Bytes

Contents

module ForestLiana
  class PieStatGetter
    attr_accessor :record

    def initialize(resource, params)
      @resource = resource
      @params = params
    end

    def perform
      if @params[:group_by_field]
        value = @resource

        @params[:filters].try(:each) do |filter|
          operator, filter_value = OperatorValueParser.parse(filter[:value])
          value = value.where("#{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 = Stat.new(value: value)
      end
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
forest_liana-1.1.18 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.17 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.16 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.15 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.14 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.13 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.12 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.11 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.10 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.8 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.7 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.6 app/services/forest_liana/pie_stat_getter.rb
forest_liana-1.1.5 app/services/forest_liana/pie_stat_getter.rb