Class: Focuslight::Graph

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/focuslight/graph.rb

Direct Known Subclasses

ComplexGraph, SimpleGraph

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

included, #logger, #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_typeObject

for complex graph construction



23
24
25
# File 'lib/focuslight/graph.rb', line 23

def c_type
  @c_type
end

#created_at_timeObject

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

#descriptionObject

Returns the value of attribute description.



19
20
21
# File 'lib/focuslight/graph.rb', line 19

def description
  @description
end

#graphObject

Returns the value of attribute graph.



19
20
21
# File 'lib/focuslight/graph.rb', line 19

def graph
  @graph
end

#idObject

Returns the value of attribute id.



19
20
21
# File 'lib/focuslight/graph.rb', line 19

def id
  @id
end

#metaObject

Returns the value of attribute meta.



20
21
22
# File 'lib/focuslight/graph.rb', line 20

def meta
  @meta
end

#numberObject

Returns the value of attribute number.



19
20
21
# File 'lib/focuslight/graph.rb', line 19

def number
  @number
end

#sectionObject

Returns the value of attribute section.



19
20
21
# File 'lib/focuslight/graph.rb', line 19

def section
  @section
end

#serviceObject

Returns the value of attribute service.



19
20
21
# File 'lib/focuslight/graph.rb', line 19

def service
  @service
end

#sortObject

Returns the value of attribute sort.



19
20
21
# File 'lib/focuslight/graph.rb', line 19

def sort
  @sort
end

#stackObject

for complex graph construction



23
24
25
# File 'lib/focuslight/graph.rb', line 23

def stack
  @stack
end

#updated_at_timeObject

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_atObject



47
48
49
# File 'lib/focuslight/graph.rb', line 47

def created_at
  @created_at_time.strftime('%Y/%m/%d %T')
end

#pathObject



43
44
45
# File 'lib/focuslight/graph.rb', line 43

def path
  [@service, @section, @graph]
end

#to_hashObject



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_atObject



51
52
53
# File 'lib/focuslight/graph.rb', line 51

def updated_at
  @updated_at_time.strftime('%Y/%m/%d %T')
end