Class: GAAPI::Row
- Inherits:
-
Object
- Object
- GAAPI::Row
- Defined in:
- lib/gaapi/row.rb
Overview
A single row from a query to Google Analytics
Instance Method Summary collapse
-
#dimensions ⇒ Object
An array of the dimension values, in the order that they appear in the dimension headers.
-
#initialize(report, row) ⇒ Row
constructor
A new instance of Row.
-
#method_missing(method, *args) ⇒ Object
Define and call methods for the columns in the report.
-
#metrics ⇒ Object
An array of the metric values, in the order that they appear in the metric headers.
- #respond_to_missing? ⇒ Boolean
-
#to_a ⇒ Object
Return the data from the row as an Array, ordered by: Headers first, in the order that they appear in the Report#headers array.
Constructor Details
#initialize(report, row) ⇒ Row
Returns a new instance of Row.
12 13 14 15 |
# File 'lib/gaapi/row.rb', line 12 def initialize(report, row) @report = report @row = row end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Define and call methods for the columns in the report.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gaapi/row.rb', line 18 def method_missing(method, *args) if (i = dimension_method_names.find_index(method)) define_singleton_method(method) do dimensions[i] end send(method) elsif (i = metric_method_names.find_index(method)) define_singleton_method(method) do convert_metric(i) end send(method) else super end end |
Instance Method Details
#dimensions ⇒ Object
An array of the dimension values, in the order that they appear in the dimension headers.
8 9 10 |
# File 'lib/gaapi/row.rb', line 8 def dimensions row["dimensions"] || [] end |
#metrics ⇒ Object
An array of the metric values, in the order that they appear in the metric headers.
36 37 38 39 40 41 |
# File 'lib/gaapi/row.rb', line 36 def metrics # NOTE: There is one entry in the `row["metrics"]` array for each data range. # Since currently we only support one date range, this following index is # always 0. row["metrics"][0]["values"] end |
#respond_to_missing? ⇒ Boolean
43 44 45 |
# File 'lib/gaapi/row.rb', line 43 def respond_to_missing? true end |
#to_a ⇒ Object
Return the data from the row as an Array, ordered by:
Headers first, in the order that they appear in the Report#headers array.
Metrics next, in the order that they appear in the Rport#metrics array.
50 51 52 |
# File 'lib/gaapi/row.rb', line 50 def to_a dimensions + metrics end |