Class: Gcloud::Bigquery::Data
- Inherits:
-
Array
- Object
- Array
- Gcloud::Bigquery::Data
- Defined in:
- lib/gcloud/bigquery/data.rb
Overview
Data
Represents Table Data as a list of name/value pairs. Also contains metadata such as etag
and total
.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#gapi ⇒ Object
The Google API Client object.
-
#table ⇒ Object
The Table object the data belongs to.
Class Method Summary collapse
-
.format_rows(rows, fields) ⇒ Object
rubocop:disable all Disabled rubocop because this implementation will not last.
- .format_values(field_types, values) ⇒ Object
-
.from_response(resp, table) ⇒ Object
New Data from a response object.
Instance Method Summary collapse
-
#etag ⇒ Object
A hash of this page of results.
-
#initialize(arr = []) ⇒ Data
constructor
:nodoc:.
-
#kind ⇒ Object
The resource type of the API response.
- #next ⇒ Object
-
#next? ⇒ Boolean
Is there a next page of data?.
-
#raw ⇒ Object
Represents Table Data as a list of positional values (array of arrays).
-
#token ⇒ Object
A token used for paging results.
-
#total ⇒ Object
The total number of rows in the complete table.
Constructor Details
#initialize(arr = []) ⇒ Data
:nodoc:
32 33 34 35 36 |
# File 'lib/gcloud/bigquery/data.rb', line 32 def initialize arr = [] #:nodoc: @table = nil @gapi = {} super arr end |
Instance Attribute Details
#gapi ⇒ Object
The Google API Client object.
30 31 32 |
# File 'lib/gcloud/bigquery/data.rb', line 30 def gapi @gapi end |
#table ⇒ Object
The Table object the data belongs to.
26 27 28 |
# File 'lib/gcloud/bigquery/data.rb', line 26 def table @table end |
Class Method Details
.format_rows(rows, fields) ⇒ Object
rubocop:disable all Disabled rubocop because this implementation will not last.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/gcloud/bigquery/data.rb', line 93 def self.format_rows rows, fields headers = fields.map { |f| f["name"] } field_types = fields.map { |f| f["type"] } Array(rows).map do |row| values = row["f"].map { |f| f["v"] } formatted_values = format_values field_types, values Hash[headers.zip formatted_values] end end |
.format_values(field_types, values) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/gcloud/bigquery/data.rb', line 104 def self.format_values field_types, values field_types.zip(values).map do |type, value| begin if value.nil? nil elsif type == "INTEGER" Integer value elsif type == "FLOAT" Float value elsif type == "BOOLEAN" (value == "true" ? true : (value == "false" ? false : nil)) else value end rescue value end end end |
.from_response(resp, table) ⇒ Object
New Data from a response object.
81 82 83 84 85 86 87 88 |
# File 'lib/gcloud/bigquery/data.rb', line 81 def self.from_response resp, table #:nodoc: formatted_rows = format_rows resp.data["rows"], table.fields data = new formatted_rows data.table = table data.gapi = resp.data data end |
Instance Method Details
#etag ⇒ Object
A hash of this page of results.
51 52 53 |
# File 'lib/gcloud/bigquery/data.rb', line 51 def etag @gapi["etag"] end |
#kind ⇒ Object
The resource type of the API response.
40 41 42 |
# File 'lib/gcloud/bigquery/data.rb', line 40 def kind @gapi["kind"] end |
#next ⇒ Object
66 67 68 69 70 |
# File 'lib/gcloud/bigquery/data.rb', line 66 def next return nil unless next? ensure_table! table.data token: token end |
#next? ⇒ Boolean
Is there a next page of data?
62 63 64 |
# File 'lib/gcloud/bigquery/data.rb', line 62 def next? !token.nil? end |
#raw ⇒ Object
Represents Table Data as a list of positional values (array of arrays). No type conversion is made, e.g. numbers are formatted as strings.
75 76 77 |
# File 'lib/gcloud/bigquery/data.rb', line 75 def raw Array(gapi["rows"]).map { |row| row["f"].map { |f| f["v"] } } end |
#token ⇒ Object
A token used for paging results.
46 47 48 |
# File 'lib/gcloud/bigquery/data.rb', line 46 def token @gapi["pageToken"] end |
#total ⇒ Object
The total number of rows in the complete table.
56 57 58 |
# File 'lib/gcloud/bigquery/data.rb', line 56 def total @gapi["totalRows"] end |