Class: Wavefront::Response::Highcharts
- Includes:
- JSON
- Defined in:
- lib/wavefront/response.rb
Instance Attribute Summary collapse
-
#highcharts ⇒ Object
readonly
Returns the value of attribute highcharts.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response, options = {}) ⇒ Highcharts
constructor
A new instance of Highcharts.
- #to_json ⇒ Object
Constructor Details
#initialize(response, options = {}) ⇒ Highcharts
Returns a new instance of Highcharts.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/wavefront/response.rb', line 86 def initialize(response, ={}) super @response = JSON.parse(response) @highcharts = [] self.timeseries.each do |series| # Highcharts expects the time in milliseconds since the epoch # And for some reason the first value tends to be BS # We also have to deal with missing (null/nil) data points. amended_data = Array.new next unless series['data'].size > 0 series['data'][1..-1].each do |time_value_pair| if time_value_pair[0] time_value_pair[0] = time_value_pair[0] * 1000 else time_value_pair[0] = "null" end amended_data << time_value_pair end @highcharts << { 'name' => series['label'], 'data' => amended_data } end end |
Instance Attribute Details
#highcharts ⇒ Object (readonly)
Returns the value of attribute highcharts.
84 85 86 |
# File 'lib/wavefront/response.rb', line 84 def highcharts @highcharts end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
84 85 86 |
# File 'lib/wavefront/response.rb', line 84 def @options end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
84 85 86 |
# File 'lib/wavefront/response.rb', line 84 def response @response end |
Instance Method Details
#to_json ⇒ Object
109 110 111 |
# File 'lib/wavefront/response.rb', line 109 def to_json @highcharts.to_json end |