Class: Hisui::Response
- Inherits:
-
Object
- Object
- Hisui::Response
- Defined in:
- lib/hisui/response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #comparing ⇒ Object
- #comparing_total ⇒ Object
- #data? ⇒ Boolean
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #primary ⇒ Object
- #primary_total ⇒ Object
- #raw_attributes ⇒ Object
- #rows ⇒ Object
- #total_values ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
5 6 7 |
# File 'lib/hisui/response.rb', line 5 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/hisui/response.rb', line 3 def response @response end |
Instance Method Details
#comparing ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/hisui/response.rb', line 35 def comparing @comparing ||= begin comparing = [] data.try(:rows).try(:each) do |row| row_data = [] row.dimensions.each do |dimension| row_data << dimension end row.try(:metrics).try(:second).try(:values).try(:each) do |value| row_data << value end comparing << Hash[fields.zip(row_data)] end comparing.map { |attributes| OpenStruct.new(attributes) } end end |
#comparing_total ⇒ Object
94 95 96 |
# File 'lib/hisui/response.rb', line 94 def comparing_total @comparing_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.try(:second).try(:values) || [])]) end |
#data? ⇒ Boolean
98 99 100 |
# File 'lib/hisui/response.rb', line 98 def data? data.row_count.to_i > 0 end |
#primary ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hisui/response.rb', line 14 def primary @primary ||= begin primary = [] data.try(:rows).try(:each) do |row| row_data = [] row.dimensions.each do |dimension| row_data << dimension end row.metrics.first.values.each do |value| row_data << value end primary << Hash[fields.zip(row_data)] end primary.map { |attributes| OpenStruct.new(attributes) } end end |
#primary_total ⇒ Object
90 91 92 |
# File 'lib/hisui/response.rb', line 90 def primary_total @primary_total ||= OpenStruct.new(Hash[metrics.zip(data.totals.first.values)]) end |
#raw_attributes ⇒ Object
9 10 11 12 |
# File 'lib/hisui/response.rb', line 9 def raw_attributes warn "[DEPRECATION] `raw_attributes` is deprecated. Please use `primary` instead." primary end |
#rows ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hisui/response.rb', line 56 def rows @rows ||= begin rows = [] data.try(:rows).try(:each) do |row| dimension_values = row.dimensions primary_data = [] comparing_data = [] row.metrics.first.values.each do |value| primary_data << value end if row.metrics.second row.metrics.second.values.each do |value| comparing_data << value end end rows << { dimensions: OpenStruct.new(Hash[dimensions.zip(dimension_values)]), primary: OpenStruct.new(Hash[metrics.zip(primary_data)]), comparing: OpenStruct.new(Hash[metrics.zip(comparing_data)]) } end rows.map { |attributes| OpenStruct.new(attributes) } end end |
#total_values ⇒ Object
85 86 87 88 |
# File 'lib/hisui/response.rb', line 85 def total_values warn "[DEPRECATION] `total_values` is deprecated. Please use `primary_total` instead." primary_total end |