Class: GrowthForecast::Path
- Inherits:
-
Object
- Object
- GrowthForecast::Path
- Defined in:
- lib/growthforecast/path.rb
Constant Summary collapse
- PATH_KEYS =
[:id,:service_name,:section_name,:graph_name,:complex]
Instance Attribute Summary collapse
-
#complex ⇒ Object
Returns the value of attribute complex.
-
#graph_name ⇒ Object
Returns the value of attribute graph_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#section_name ⇒ Object
Returns the value of attribute section_name.
-
#service_name ⇒ Object
Returns the value of attribute service_name.
Class Method Summary collapse
Instance Method Summary collapse
- #complex? ⇒ Boolean
-
#initialize(obj) ⇒ Path
constructor
A new instance of Path.
- #to_graph ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(obj) ⇒ Path
Returns a new instance of Path.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/growthforecast/path.rb', line 21 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 @id = obj[:id].to_i @service_name = obj[:service_name] @section_name = obj[:section_name] @graph_name = obj[:graph_name] @complex = obj[:complex] ? true : false end |
Instance Attribute Details
#complex ⇒ Object
Returns the value of attribute complex.
7 8 9 |
# File 'lib/growthforecast/path.rb', line 7 def complex @complex end |
#graph_name ⇒ Object
Returns the value of attribute graph_name.
6 7 8 |
# File 'lib/growthforecast/path.rb', line 6 def graph_name @graph_name end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/growthforecast/path.rb', line 6 def id @id end |
#section_name ⇒ Object
Returns the value of attribute section_name.
6 7 8 |
# File 'lib/growthforecast/path.rb', line 6 def section_name @section_name end |
#service_name ⇒ Object
Returns the value of attribute service_name.
6 7 8 |
# File 'lib/growthforecast/path.rb', line 6 def service_name @service_name end |
Class Method Details
.path?(obj) ⇒ Boolean
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/growthforecast/path.rb', line 10 def self.path?(obj) if obj.is_a?(String) obj = JSON.parse(obj) end keys = obj.keys.size if keys >= 4 && keys <= 5 && obj.keys.map(&:to_sym).reduce(true){|r,k| r && PATH_KEYS.include?(k)} return true end false end |
Instance Method Details
#complex? ⇒ Boolean
36 37 38 |
# File 'lib/growthforecast/path.rb', line 36 def complex? @complex end |
#to_graph ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/growthforecast/path.rb', line 47 def to_graph if @complex GrowthForecast::Complex.new({ complex: true, id: @id, service_name: @service_name, section_name: @section_name, graph_name: @graph_name }) else GrowthForecast::Graph.new({ complex: false, id: @id, service_name: @service_name, section_name: @section_name, graph_name: @graph_name }) end end |
#to_json ⇒ Object
40 41 42 43 44 45 |
# File 'lib/growthforecast/path.rb', line 40 def to_json { 'id' => @id, 'complex' => @complex, 'service_name' => @service_name, 'section_name' => @section_name, 'graph_name' => @graph_name, }.to_json end |