Class: AnalyticsOps::BigQuery::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/analytics_ops/bigquery/definition.rb,
sig/analytics_ops.rbs

Overview

Immutable, bounded request for one fixed BigQuery report recipe.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, start_date:, end_date:, limit: 1_000) ⇒ Definition

Returns a new instance of Definition.



14
15
16
17
18
19
20
21
22
# File 'lib/analytics_ops/bigquery/definition.rb', line 14

def initialize(name:, start_date:, end_date:, limit: 1_000)
  @name = validate_name(name)
  @start_suffix = suffix(start_date, "start_date")
  @end_suffix = suffix(end_date, "end_date")
  raise InvalidRequestError, "BigQuery start_date must not be after end_date" if @start_suffix > @end_suffix

  @limit = bounded_integer(limit, "limit", 1, 10_000)
  freeze
end

Instance Attribute Details

#end_suffixString (readonly)

Returns the value of attribute end_suffix.

Returns:

  • (String)


12
13
14
# File 'lib/analytics_ops/bigquery/definition.rb', line 12

def end_suffix
  @end_suffix
end

#limitInteger (readonly)

Returns the value of attribute limit.

Returns:

  • (Integer)


12
13
14
# File 'lib/analytics_ops/bigquery/definition.rb', line 12

def limit
  @limit
end

#nameString (readonly)

Returns the value of attribute name.

Returns:

  • (String)


12
13
14
# File 'lib/analytics_ops/bigquery/definition.rb', line 12

def name
  @name
end

#start_suffixString (readonly)

Returns the value of attribute start_suffix.

Returns:

  • (String)


12
13
14
# File 'lib/analytics_ops/bigquery/definition.rb', line 12

def start_suffix
  @start_suffix
end

Class Method Details

.from_date_ranges(name, date_ranges, limit: 1_000, today: Date.today) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/analytics_ops/bigquery/definition.rb', line 24

def self.from_date_ranges(name, date_ranges, limit: 1_000, today: Date.today)
  unless date_ranges.is_a?(Array) && date_ranges.length == 1
    raise InvalidRequestError, "BigQuery reports require exactly one date range"
  end

  range = date_ranges.first
  new(
    name:,
    start_date: resolve_date(range.fetch("start_date"), today:),
    end_date: resolve_date(range.fetch("end_date"), today:),
    limit:
  )
rescue KeyError
  raise InvalidRequestError, "BigQuery report date range is invalid"
end

Instance Method Details

#to_hrecord

Returns:

  • (record)


40
41
42
# File 'lib/analytics_ops/bigquery/definition.rb', line 40

def to_h
  { "name" => name, "start_suffix" => start_suffix, "end_suffix" => end_suffix, "limit" => limit }
end