Class: GrowthForecast::Complex
- Inherits:
-
Object
- Object
- GrowthForecast::Complex
- Defined in:
- lib/growthforecast/complex.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#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.
-
#graph_name ⇒ Object
Returns the value of attribute graph_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#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.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#sumup ⇒ Object
Returns the value of attribute sumup.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #complex? ⇒ Boolean
-
#initialize(obj) ⇒ Complex
constructor
TODO strict validations.
- #to_json ⇒ Object
Constructor Details
#initialize(obj) ⇒ Complex
TODO strict validations
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/growthforecast/complex.rb', line 12 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 not obj[:complex] raise ArgumentError, "non-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] @sort = (obj[:sort] || 19).to_i @sumup = obj[:sumup] ? true : false @data = (obj[:data] || []).map{|d| d.is_a?(Item) ? d : Item.new(d)} @number = (obj[:number] || 0).to_i @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
#created_at ⇒ Object
Returns the value of attribute created_at.
8 9 10 |
# File 'lib/growthforecast/complex.rb', line 8 def created_at @created_at end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/growthforecast/complex.rb', line 7 def data @data end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/growthforecast/complex.rb', line 6 def description @description end |
#graph_name ⇒ Object
Returns the value of attribute graph_name.
5 6 7 |
# File 'lib/growthforecast/complex.rb', line 5 def graph_name @graph_name end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/growthforecast/complex.rb', line 5 def id @id end |
#number ⇒ Object
Returns the value of attribute number.
8 9 10 |
# File 'lib/growthforecast/complex.rb', line 8 def number @number end |
#section_name ⇒ Object
Returns the value of attribute section_name.
5 6 7 |
# File 'lib/growthforecast/complex.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/complex.rb', line 5 def service_name @service_name end |
#sort ⇒ Object
Returns the value of attribute sort.
6 7 8 |
# File 'lib/growthforecast/complex.rb', line 6 def sort @sort end |
#sumup ⇒ Object
Returns the value of attribute sumup.
6 7 8 |
# File 'lib/growthforecast/complex.rb', line 6 def sumup @sumup end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
8 9 10 |
# File 'lib/growthforecast/complex.rb', line 8 def updated_at @updated_at end |
Instance Method Details
#complex? ⇒ Boolean
37 38 39 |
# File 'lib/growthforecast/complex.rb', line 37 def complex? true end |
#to_json ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/growthforecast/complex.rb', line 41 def to_json { 'complex' => true, 'id' => @id, 'service_name' => @service_name, 'section_name' => @section_name, 'graph_name' => @graph_name, 'description' => @description, 'sort' => @sort, 'sumup' => @sumup, 'data' => @data.map(&:to_hash), 'number' => @number, 'created_at' => (@created_at ? @created_at.strftime(GrowthForecast::TIME_FORMAT) : nil), 'updated_at' => (@updated_at ? @updated_at.strftime(GrowthForecast::TIME_FORMAT) : nil), }.to_json end |