Class: ForestLiana::ValueStatGetter

Inherits:
Object
  • Object
show all
Defined in:
app/services/forest_liana/value_stat_getter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, params) ⇒ ValueStatGetter

Returns a new instance of ValueStatGetter.



5
6
7
8
# File 'app/services/forest_liana/value_stat_getter.rb', line 5

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

Instance Attribute Details

#recordObject

Returns the value of attribute record.



3
4
5
# File 'app/services/forest_liana/value_stat_getter.rb', line 3

def record
  @record
end

Instance Method Details

#performObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/forest_liana/value_stat_getter.rb', line 10

def perform
  return if @params[:aggregate].blank?
  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

  @record = Model::Stat.new(value: count(value))
end