class Focuslight::Graph
Attributes
c_type[RW]
created_at_time[RW]
description[RW]
graph[RW]
id[RW]
meta[RW]
number[RW]
section[RW]
service[RW]
sort[RW]
stack[RW]
updated_at_time[RW]
Public Class Methods
concrete(row)
click to toggle source
# 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)
click to toggle source
# 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
new(row)
click to toggle source
# 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
Public Instance Methods
created_at()
click to toggle source
# File lib/focuslight/graph.rb, line 47 def created_at @created_at_time.strftime('%Y/%m/%d %T') end
path()
click to toggle source
# File lib/focuslight/graph.rb, line 43 def path [@service, @section, @graph] end
to_hash()
click to toggle source
# 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()
click to toggle source
# File lib/focuslight/graph.rb, line 51 def updated_at @updated_at_time.strftime('%Y/%m/%d %T') end