Class: AnalyticsOps::BigQuery::Definition
- Inherits:
-
Object
- Object
- AnalyticsOps::BigQuery::Definition
- 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
-
#end_suffix ⇒ String
readonly
Returns the value of attribute end_suffix.
-
#limit ⇒ Integer
readonly
Returns the value of attribute limit.
-
#name ⇒ String
readonly
Returns the value of attribute name.
-
#start_suffix ⇒ String
readonly
Returns the value of attribute start_suffix.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name:, start_date:, end_date:, limit: 1_000) ⇒ Definition
constructor
A new instance of Definition.
- #to_h ⇒ record
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_suffix ⇒ String (readonly)
Returns the value of attribute end_suffix.
12 13 14 |
# File 'lib/analytics_ops/bigquery/definition.rb', line 12 def end_suffix @end_suffix end |
#limit ⇒ Integer (readonly)
Returns the value of attribute limit.
12 13 14 |
# File 'lib/analytics_ops/bigquery/definition.rb', line 12 def limit @limit end |
#name ⇒ String (readonly)
Returns the value of attribute name.
12 13 14 |
# File 'lib/analytics_ops/bigquery/definition.rb', line 12 def name @name end |
#start_suffix ⇒ String (readonly)
Returns the value of attribute start_suffix.
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_h ⇒ 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 |