Class: GAAPI::Report
- Inherits:
-
Object
- Object
- GAAPI::Report
- Defined in:
- lib/gaapi/report.rb
Overview
A single report from a query to Google Analytics
Instance Attribute Summary collapse
-
#report ⇒ Object
readonly
Returns the value of attribute report.
Instance Method Summary collapse
-
#dimensions ⇒ Object
An array of the dimensions, in the order that they appear in the response.
-
#dimensions? ⇒ Boolean
True if dimensions were returned.
-
#headers ⇒ Object
An array of the dimensions first and then the metrics, in the order that they appear in the response.
-
#initialize(response, report) ⇒ Report
constructor
A new instance of Report.
-
#metric_type(i) ⇒ Object
An array of the metric names, in the order that they appear in the response.
-
#metrics ⇒ Object
An array of the metric names, in the order that they appear in the response.
-
#rows ⇒ Object
The data rows in the report.
-
#totals ⇒ Object
The totals, if there were any.
-
#totals? ⇒ Boolean
True if there totals were returned from the query.
Constructor Details
#initialize(response, report) ⇒ Report
Returns a new instance of Report.
22 23 24 25 |
# File 'lib/gaapi/report.rb', line 22 def initialize(response, report) @response = response @report = report end |
Instance Attribute Details
#report ⇒ Object (readonly)
Returns the value of attribute report.
26 27 28 |
# File 'lib/gaapi/report.rb', line 26 def report @report end |
Instance Method Details
#dimensions ⇒ Object
An array of the dimensions, in the order that they appear in the response.
7 8 9 |
# File 'lib/gaapi/report.rb', line 7 def dimensions report["columnHeader"]["dimensions"] || [] end |
#dimensions? ⇒ Boolean
Returns True if dimensions were returned.
12 13 14 |
# File 'lib/gaapi/report.rb', line 12 def dimensions? !report["columnHeader"]["dimensions"].nil? end |
#headers ⇒ Object
An array of the dimensions first and then the metrics, in the order that they appear in the response.
18 19 20 |
# File 'lib/gaapi/report.rb', line 18 def headers dimensions + metrics end |
#metric_type(i) ⇒ Object
An array of the metric names, in the order that they appear in the response.
29 30 31 |
# File 'lib/gaapi/report.rb', line 29 def metric_type(i) report["columnHeader"]["metricHeader"]["metricHeaderEntries"][i]["type"] end |
#metrics ⇒ Object
An array of the metric names, in the order that they appear in the response.
34 35 36 |
# File 'lib/gaapi/report.rb', line 34 def metrics report["columnHeader"]["metricHeader"]["metricHeaderEntries"].map { |metric| metric["name"] } end |
#rows ⇒ Object
The data rows in the report.
39 40 41 |
# File 'lib/gaapi/report.rb', line 39 def rows report["data"]["rows"].map { |row| Row.new(self, row) } end |
#totals ⇒ Object
The totals, if there were any.
44 45 46 |
# File 'lib/gaapi/report.rb', line 44 def totals Array.new(dimensions.size) + report["data"]["totals"][0]["values"] end |
#totals? ⇒ Boolean
Returns True if there totals were returned from the query.
49 50 51 |
# File 'lib/gaapi/report.rb', line 49 def totals? report["data"]["totals"] end |