Sha256: aafd27b8c9f7507711c004110416cfea919ae6e59d8ca5b01dbf64bc9882f3b3

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

class Segment
  include Virtus.model

  GROUP_BY_FIELDS = %w(
    advertiser_id
    advertisement_id
    campaign_id
    channel_id
    app_id
    exchange_id
    publisher_id
    agency_id
    site_id
    third_party_id
    supply_id
  ).freeze

  COMPOUND_METRICS_FIELDS =
    Config.compound_metric_types.reject { |m| m.include?('render') }.map(&:pluralize)

  AGGREGATED_METRIC_FIELDS = Config.aggregated_metric_types.map(&:pluralize)
  COST_METRIC_FIELDS = Config.cost_metrics

  VERIFIED_FIELDS =
    (GROUP_BY_FIELDS +
      AGGREGATED_METRIC_FIELDS +
      COMPOUND_METRICS_FIELDS +
      COST_METRIC_FIELDS).sort.freeze

  attribute :shard, Integer
  attribute :siblings, Array[String]

  GROUP_BY_FIELDS.each do |f|
    attribute f.to_sym, String
  end

  AGGREGATED_METRIC_FIELDS.each do |f|
    attribute f.to_sym, Integer
  end

  COMPOUND_METRICS_FIELDS.each do |f|
    attribute f.to_sym, Integer
  end

  COST_METRIC_FIELDS.each do |f|
    attribute f.to_sym, Float
  end

  def hash
    Hashtastic::DictionaryValuesHasher.call(attributes, VERIFIED_FIELDS)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voucher-0.3.0 lib/voucher/model/segment.rb