Class: Focuslight::Graph
- Inherits:
-
Object
- Object
- Focuslight::Graph
- Includes:
- Logger
- Defined in:
- lib/focuslight/graph.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#c_type ⇒ Object
for complex graph construction.
-
#created_at_time ⇒ Object
Returns the value of attribute created_at_time.
-
#description ⇒ Object
Returns the value of attribute description.
-
#graph ⇒ Object
Returns the value of attribute graph.
-
#id ⇒ Object
Returns the value of attribute id.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#number ⇒ Object
Returns the value of attribute number.
-
#section ⇒ Object
Returns the value of attribute section.
-
#service ⇒ Object
Returns the value of attribute service.
-
#sort ⇒ Object
Returns the value of attribute sort.
-
#stack ⇒ Object
for complex graph construction.
-
#updated_at_time ⇒ Object
Returns the value of attribute updated_at_time.
Class Method Summary collapse
Instance Method Summary collapse
- #created_at ⇒ Object
-
#initialize(row) ⇒ Graph
constructor
A new instance of Graph.
- #path ⇒ Object
- #to_hash ⇒ Object
- #updated_at ⇒ Object
Methods included from Logger
Constructor Details
#initialize(row) ⇒ Graph
Returns a new instance of Graph.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/focuslight/graph.rb', line 25 def initialize(row) @row_hash = row @id = row[:id] @service = row[:service_name] @section = row[:section_name] @graph = row[:graph_name] @number = row[:number].to_i # NOT NULL DEFAULT 0 @description = row[:description] || '' @sort = row[:sort].to_i # NOT NULL DEFAULT 0 @meta = row[:meta] @parsed_meta = JSON.parse(@meta || '{}', :symbolize_names => true) @created_at_time = Time.at(row[:created_at].to_i) @updated_at_time = Time.at(row[:updated_at].to_i) end |
Instance Attribute Details
#c_type ⇒ Object
for complex graph construction
23 24 25 |
# File 'lib/focuslight/graph.rb', line 23 def c_type @c_type end |
#created_at_time ⇒ Object
Returns the value of attribute created_at_time.
21 22 23 |
# File 'lib/focuslight/graph.rb', line 21 def created_at_time @created_at_time end |
#description ⇒ Object
Returns the value of attribute description.
19 20 21 |
# File 'lib/focuslight/graph.rb', line 19 def description @description end |
#graph ⇒ Object
Returns the value of attribute graph.
19 20 21 |
# File 'lib/focuslight/graph.rb', line 19 def graph @graph end |
#id ⇒ Object
Returns the value of attribute id.
19 20 21 |
# File 'lib/focuslight/graph.rb', line 19 def id @id end |
#meta ⇒ Object
Returns the value of attribute meta.
20 21 22 |
# File 'lib/focuslight/graph.rb', line 20 def @meta end |
#number ⇒ Object
Returns the value of attribute number.
19 20 21 |
# File 'lib/focuslight/graph.rb', line 19 def number @number end |
#section ⇒ Object
Returns the value of attribute section.
19 20 21 |
# File 'lib/focuslight/graph.rb', line 19 def section @section end |
#service ⇒ Object
Returns the value of attribute service.
19 20 21 |
# File 'lib/focuslight/graph.rb', line 19 def service @service end |
#sort ⇒ Object
Returns the value of attribute sort.
19 20 21 |
# File 'lib/focuslight/graph.rb', line 19 def sort @sort end |
#stack ⇒ Object
for complex graph construction
23 24 25 |
# File 'lib/focuslight/graph.rb', line 23 def stack @stack end |
#updated_at_time ⇒ Object
Returns the value of attribute updated_at_time.
21 22 23 |
# File 'lib/focuslight/graph.rb', line 21 def updated_at_time @updated_at_time end |
Class Method Details
.concrete(row) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/focuslight/graph.rb', line 11 def self.concrete(row) if row.has_key?(:mode) && row.has_key?(:type) Focuslight::SimpleGraph.new(row) else Focuslight::ComplexGraph.new(row) end end |
.hash2request(hash) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/focuslight/graph.rb', line 63 def self.hash2request(hash) hash = hash.dup is_complex = hash.delete(:complex) hash.delete(:id) hash.delete(:created_at) hash.delete(:updated_at) return hash unless is_complex ##TODO concrete? hash.delete(:number) hash[:sumup] = (hash[:sumup] ? '1' : '0') data_rows = hash.delete(:data) first = data_rows.shift hash['path-1'.to_sym] = first[:graph_id] hash['type-1'.to_sym] = first[:type] p2 = 'path-2'.to_sym t2 = 'type-2'.to_sym s2 = 'stack-2'.to_sym hash[p2] = [] hash[t2] = [] hash[s2] = [] data_rows.each do |row| hash[p2] << row[:graph_id] hash[t2] << row[:type] hash[s2] << (row[:stack] ? '1' : '0') end hash ##TODO concrete? end |
Instance Method Details
#created_at ⇒ Object
47 48 49 |
# File 'lib/focuslight/graph.rb', line 47 def created_at @created_at_time.strftime('%Y/%m/%d %T') end |
#path ⇒ Object
43 44 45 |
# File 'lib/focuslight/graph.rb', line 43 def path [@service, @section, @graph] end |
#to_hash ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/focuslight/graph.rb', line 55 def to_hash { id: @id, service_name: @service, section_name: @section, graph_name: @graph, number: @number, description: @description, sort: @sort, created_at: self.created_at(), updated_at: self.updated_at(), } end |
#updated_at ⇒ Object
51 52 53 |
# File 'lib/focuslight/graph.rb', line 51 def updated_at @updated_at_time.strftime('%Y/%m/%d %T') end |