Class: GrowthForecast::Graph
- Inherits:
-
Object
- Object
- GrowthForecast::Graph
- Defined in:
- lib/growthforecast/graph.rb
Instance Attribute Summary collapse
-
#adjust ⇒ Object
Returns the value of attribute adjust.
-
#adjustval ⇒ Object
Returns the value of attribute adjustval.
-
#color ⇒ Object
Returns the value of attribute color.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#data ⇒ Object
Returns the value of attribute data.
-
#description ⇒ Object
Returns the value of attribute description.
-
#gmode ⇒ Object
Returns the value of attribute gmode.
-
#graph_name ⇒ Object
Returns the value of attribute graph_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#llimit ⇒ Object
Returns the value of attribute llimit.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#number ⇒ Object
Returns the value of attribute number.
-
#section_name ⇒ Object
Returns the value of attribute section_name.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
-
#sllimit ⇒ Object
Returns the value of attribute sllimit.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#stype ⇒ Object
Returns the value of attribute stype.
-
#sulimit ⇒ Object
Returns the value of attribute sulimit.
-
#type ⇒ Object
Returns the value of attribute type.
-
#ulimit ⇒ Object
Returns the value of attribute ulimit.
-
#unit ⇒ Object
Returns the value of attribute unit.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #complex? ⇒ Boolean
-
#initialize(obj) ⇒ Graph
constructor
TODO strict validations.
- #to_json ⇒ Object
Constructor Details
#initialize(obj) ⇒ Graph
TODO strict validations
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/growthforecast/graph.rb', line 13 def initialize(obj) if obj.is_a?(String) obj = JSON.parse(obj) end obj.keys.each do |k| obj[k.to_sym] = obj.delete(k) end if obj[:complex] raise ArgumentError, "complex graph is for GrowthForecast::Complex" end @id = obj[:id] ? obj[:id].to_i : nil @service_name = obj[:service_name] @section_name = obj[:section_name] @graph_name = obj[:graph_name] @description = obj[:description] @mode = obj[:mode] || 'gauge' @sort = (obj[:sort] || 19).to_i @color = obj[:color] @gmode = obj[:gmode] || 'gauge' @type = obj[:type] || 'AREA' @ulimit = obj[:ulimit] || 1000000000 @llimit = obj[:llimit] || -1000000000 @stype = obj[:stype] || 'AREA' @sulimit = obj[:sulimit] || 100000 @sllimit = obj[:sllimit] || -100000 @adjust = obj[:adjust] || '*' @adjustval = (obj[:adjustval] || 1).to_i @unit = obj[:unit] || '' @number = (obj[:number] || 0).to_i @data = obj[:data] || [] @created_at = obj[:created_at] ? Time.strptime(obj[:created_at], GrowthForecast::TIME_FORMAT) : nil @updated_at = obj[:updated_at] ? Time.strptime(obj[:updated_at], GrowthForecast::TIME_FORMAT) : nil end |
Instance Attribute Details
#adjust ⇒ Object
Returns the value of attribute adjust.
8 9 10 |
# File 'lib/growthforecast/graph.rb', line 8 def adjust @adjust end |
#adjustval ⇒ Object
Returns the value of attribute adjustval.
8 9 10 |
# File 'lib/growthforecast/graph.rb', line 8 def adjustval @adjustval end |
#color ⇒ Object
Returns the value of attribute color.
6 7 8 |
# File 'lib/growthforecast/graph.rb', line 6 def color @color end |
#created_at ⇒ Object
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/growthforecast/graph.rb', line 9 def created_at @created_at end |
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/growthforecast/graph.rb', line 9 def data @data end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/growthforecast/graph.rb', line 6 def description @description end |
#gmode ⇒ Object
Returns the value of attribute gmode.
6 7 8 |
# File 'lib/growthforecast/graph.rb', line 6 def gmode @gmode end |
#graph_name ⇒ Object
Returns the value of attribute graph_name.
5 6 7 |
# File 'lib/growthforecast/graph.rb', line 5 def graph_name @graph_name end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/growthforecast/graph.rb', line 5 def id @id end |
#llimit ⇒ Object
Returns the value of attribute llimit.
7 8 9 |
# File 'lib/growthforecast/graph.rb', line 7 def llimit @llimit end |
#mode ⇒ Object
Returns the value of attribute mode.
6 7 8 |
# File 'lib/growthforecast/graph.rb', line 6 def mode @mode end |
#number ⇒ Object
Returns the value of attribute number.
9 10 11 |
# File 'lib/growthforecast/graph.rb', line 9 def number @number end |
#section_name ⇒ Object
Returns the value of attribute section_name.
5 6 7 |
# File 'lib/growthforecast/graph.rb', line 5 def section_name @section_name end |
#service_name ⇒ Object
Returns the value of attribute service_name.
5 6 7 |
# File 'lib/growthforecast/graph.rb', line 5 def service_name @service_name end |
#sllimit ⇒ Object
Returns the value of attribute sllimit.
7 8 9 |
# File 'lib/growthforecast/graph.rb', line 7 def sllimit @sllimit end |
#sort ⇒ Object
Returns the value of attribute sort.
6 7 8 |
# File 'lib/growthforecast/graph.rb', line 6 def sort @sort end |
#stype ⇒ Object
Returns the value of attribute stype.
7 8 9 |
# File 'lib/growthforecast/graph.rb', line 7 def stype @stype end |
#sulimit ⇒ Object
Returns the value of attribute sulimit.
7 8 9 |
# File 'lib/growthforecast/graph.rb', line 7 def sulimit @sulimit end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/growthforecast/graph.rb', line 7 def type @type end |
#ulimit ⇒ Object
Returns the value of attribute ulimit.
7 8 9 |
# File 'lib/growthforecast/graph.rb', line 7 def ulimit @ulimit end |
#unit ⇒ Object
Returns the value of attribute unit.
8 9 10 |
# File 'lib/growthforecast/graph.rb', line 8 def unit @unit end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
9 10 11 |
# File 'lib/growthforecast/graph.rb', line 9 def updated_at @updated_at end |
Instance Method Details
#complex? ⇒ Boolean
50 51 52 |
# File 'lib/growthforecast/graph.rb', line 50 def complex? false end |
#to_json ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/growthforecast/graph.rb', line 54 def to_json if @color.nil? raise RuntimeError, "cannot stringify as json without 'color' parameter" end { 'complex' => false, 'id' => @id, 'service_name' => @service_name, 'section_name' => @section_name, 'graph_name' => @graph_name, 'description' => @description, 'mode' => @mode, 'sort' => @sort, 'color' => @color, 'gmode' => @gmode, 'type' => @type, 'ulimit' => @ulimit, 'llimit' => @llimit, 'stype' => @stype, 'sulimit' => @sulimit, 'sllimit' => @sllimit, 'adjust' => @adjust, 'adjustval' => @adjustval, 'unit' => @unit, 'number' => @number, 'data' => @data, 'created_at' => @created_at.strftime(GrowthForecast::TIME_FORMAT), 'updated_at' => @updated_at.strftime(GrowthForecast::TIME_FORMAT) }.to_json end |