Class: SupplejackApi::InteractionUpdaters::SetMetrics
- Inherits:
-
Object
- Object
- SupplejackApi::InteractionUpdaters::SetMetrics
- Defined in:
- app/models/supplejack_api/interaction_updaters/set_metrics.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize ⇒ SetMetrics
constructor
A new instance of SetMetrics.
- #process(set_interactions) ⇒ Object
Constructor Details
#initialize ⇒ SetMetrics
Returns a new instance of SetMetrics.
7 8 9 |
# File 'app/models/supplejack_api/interaction_updaters/set_metrics.rb', line 7 def initialize @model = SupplejackApi::InteractionModels::Set end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'app/models/supplejack_api/interaction_updaters/set_metrics.rb', line 5 def model @model end |
Instance Method Details
#process(set_interactions) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/supplejack_api/interaction_updaters/set_metrics.rb', line 11 def process(set_interactions) unique_facets = set_interactions.map(&:facet).uniq unique_facets.each do |facet| metric = SupplejackApi::UsageMetrics.find_or_create_by( date: Date.current, record_field_value: facet ) do |um| um.date = Date.current um.record_field_value = facet end records_added = set_interactions.count { |x| x.facet == facet } metric.records_added_to_user_sets += records_added metric.save! end true end |