Class: AnalyticsOps::Reports::OverviewResult

Inherits:
Object
  • Object
show all
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 =

Returns:

  • (Integer)
5
PROPERTY_ID =
/\A\d{1,50}\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_id:, reports:) ⇒ OverviewResult

Returns a new instance of OverviewResult.

Parameters:

  • property_id: (String)
  • reports: (Array[Result])

Raises:



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_idString (readonly)

Returns the value of attribute property_id.

Returns:

  • (String)


10
11
12
# File 'lib/analytics_ops/reports/overview_result.rb', line 10

def property_id
  @property_id
end

#property_quotarecord (readonly)

Returns the value of attribute property_quota.

Returns:

  • (record)


10
11
12
# File 'lib/analytics_ops/reports/overview_result.rb', line 10

def property_quota
  @property_quota
end

#reportsArray[Result] (readonly)

Returns the value of attribute reports.

Returns:



10
11
12
# File 'lib/analytics_ops/reports/overview_result.rb', line 10

def reports
  @reports
end

Instance Method Details

#report(name) ⇒ Result

Parameters:

  • name (String, Symbol)

Returns:



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_hrecord

Returns:

  • (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