Class: Garb::ReportResponse
- Inherits:
-
Object
- Object
- Garb::ReportResponse
- Defined in:
- lib/garb/report_response.rb
Defined Under Namespace
Classes: Dimension, Entry, Metric
Instance Method Summary collapse
-
#initialize(response_body) ⇒ ReportResponse
constructor
include Enumerable.
- #parse ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(response_body) ⇒ ReportResponse
include Enumerable
5 6 7 |
# File 'lib/garb/report_response.rb', line 5 def initialize(response_body) @xml = response_body end |
Instance Method Details
#parse ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/garb/report_response.rb', line 9 def parse entries = Entry.parse(@xml) @results = entries.collect do |entry| hash = {} entry.metrics.each do |m| name = m.name.sub(/^ga\:/,'').underscored hash.merge!({name => m.value}) end entry.dimensions.each do |d| name = d.name.sub(/^ga\:/,'').underscored hash.merge!({name => d.value}) end OpenStruct.new(hash) end end |
#results ⇒ Object
29 30 31 |
# File 'lib/garb/report_response.rb', line 29 def results @results || parse end |