Class: AnalyticsOps::Reports::OverviewResult
- Inherits:
-
Object
- Object
- AnalyticsOps::Reports::OverviewResult
- Defined in:
- lib/analytics_ops/reports/overview_result.rb,
sig/analytics_ops.rbs
Overview
Immutable collection of the bounded reports that make up an overview.
Constant Summary collapse
- MAX_REPORTS =
5- PROPERTY_ID =
/\A\d{1,50}\z/
Instance Attribute Summary collapse
-
#property_id ⇒ String
readonly
Returns the value of attribute property_id.
-
#property_quota ⇒ record
readonly
Returns the value of attribute property_quota.
-
#reports ⇒ Array[Result]
readonly
Returns the value of attribute reports.
Instance Method Summary collapse
-
#initialize(property_id:, reports:) ⇒ OverviewResult
constructor
A new instance of OverviewResult.
- #report(name) ⇒ Result
- #to_h ⇒ record
Constructor Details
#initialize(property_id:, reports:) ⇒ OverviewResult
Returns a new instance of OverviewResult.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/analytics_ops/reports/overview_result.rb', line 12 def initialize(property_id:, reports:) unless property_id.is_a?(String) && PROPERTY_ID.match?(property_id) raise RemoteError, "Overview property ID is invalid" end unless reports.is_a?(Array) && reports.length.between?(1, MAX_REPORTS) && reports.all? { |report| report.is_a?(Result) && report.kind == "standard" } raise RemoteError, "Overview must contain 1 to #{MAX_REPORTS} standard report results" end names = reports.map(&:name) raise RemoteError, "Overview report names must be unique" unless names.uniq.length == names.length @property_id = property_id.dup.freeze @reports = reports.dup.freeze @property_quota = Canonical.immutable(latest_quota) freeze end |
Instance Attribute Details
#property_id ⇒ String (readonly)
Returns the value of attribute property_id.
10 11 12 |
# File 'lib/analytics_ops/reports/overview_result.rb', line 10 def property_id @property_id end |
#property_quota ⇒ record (readonly)
Returns the value of attribute property_quota.
10 11 12 |
# File 'lib/analytics_ops/reports/overview_result.rb', line 10 def property_quota @property_quota end |
#reports ⇒ Array[Result] (readonly)
Returns the value of attribute reports.
10 11 12 |
# File 'lib/analytics_ops/reports/overview_result.rb', line 10 def reports @reports end |
Instance Method Details
#report(name) ⇒ Result
30 31 32 33 |
# File 'lib/analytics_ops/reports/overview_result.rb', line 30 def report(name) reports.find { |result| result.name == name.to_s } || raise(KeyError, "Unknown overview report #{name.inspect}") end |
#to_h ⇒ record
35 36 37 38 39 40 41 |
# File 'lib/analytics_ops/reports/overview_result.rb', line 35 def to_h { "property_id" => property_id, "reports" => reports.map(&:to_h), "property_quota" => property_quota } end |