Class: AnalyticsOps::Reports::Metadata
- Inherits:
-
Object
- Object
- AnalyticsOps::Reports::Metadata
- Defined in:
- lib/analytics_ops/reports/metadata.rb,
sig/analytics_ops.rbs
Overview
Immutable property-aware catalog of report dimensions and metrics.
Instance Attribute Summary collapse
-
#dimensions ⇒ Array[Field]
readonly
Returns the value of attribute dimensions.
-
#metrics ⇒ Array[Field]
readonly
Returns the value of attribute metrics.
-
#property_id ⇒ String
readonly
Returns the value of attribute property_id.
Instance Method Summary collapse
-
#initialize(property_id:, dimensions:, metrics:) ⇒ Metadata
constructor
A new instance of Metadata.
- #search(query = nil, kind: nil) ⇒ Array[Field]
- #to_h ⇒ record
Constructor Details
#initialize(property_id:, dimensions:, metrics:) ⇒ Metadata
Returns a new instance of Metadata.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/analytics_ops/reports/metadata.rb', line 16 def initialize(property_id:, dimensions:, metrics:) unless property_id.is_a?(String) && property_id.match?(/\A\d{1,50}\z/) raise RemoteError, "Report metadata property ID is invalid" end unless dimensions.is_a?(Array) && dimensions.all?(Field) && metrics.is_a?(Array) && metrics.all?(Field) raise RemoteError, "Report metadata fields are invalid" end @property_id = property_id.dup.freeze @dimensions = dimensions.dup.freeze @metrics = metrics.dup.freeze freeze end |
Instance Attribute Details
#dimensions ⇒ Array[Field] (readonly)
Returns the value of attribute dimensions.
14 15 16 |
# File 'lib/analytics_ops/reports/metadata.rb', line 14 def dimensions @dimensions end |
#metrics ⇒ Array[Field] (readonly)
Returns the value of attribute metrics.
14 15 16 |
# File 'lib/analytics_ops/reports/metadata.rb', line 14 def metrics @metrics end |
#property_id ⇒ String (readonly)
Returns the value of attribute property_id.
14 15 16 |
# File 'lib/analytics_ops/reports/metadata.rb', line 14 def property_id @property_id end |
Instance Method Details
#search(query = nil, kind: nil) ⇒ Array[Field]
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/analytics_ops/reports/metadata.rb', line 31 def search(query = nil, kind: nil) values = fields_for(kind) return values.freeze if query.nil? validate_query!(query) return values.freeze if query.empty? needle = query.downcase matches = values.select do |field| [field.api_name, field.ui_name, field.description, field.category].compact.any? do |value| value.downcase.include?(needle) end end matches.freeze end |
#to_h ⇒ record
47 48 49 50 51 52 53 |
# File 'lib/analytics_ops/reports/metadata.rb', line 47 def to_h { "property_id" => property_id, "dimensions" => dimensions.map(&:to_h), "metrics" => metrics.map(&:to_h) } end |