Class: Focuslight::SimpleGraph

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

Constant Summary collapse

COLUMNS =
%w(service_name section_name graph_name number mode color llimit created_at updated_at)
PLACEHOLDERS =
COLUMNS.map{|c| '?'}

Instance Attribute Summary collapse

Attributes inherited from Graph

#c_type, #created_at_time, #description, #graph, #id, #meta, #number, #section, #service, #sort, #stack, #updated_at_time

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Graph

concrete, #created_at, hash2request, #path, #updated_at

Methods included from Logger

included, #logger, #logger=

Constructor Details

#initialize(row) ⇒ SimpleGraph

Returns a new instance of SimpleGraph.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/focuslight/graph.rb', line 107

def initialize(row)
  super

  @mode = row[:mode] || 'gauge' # NOT NULL DEFAULT 'gauge'
  @color = row[:color] || '#00CC00' # NOT NULL DEFAULT '#00CC00'
  @ulimit = row[:ulimit] || 1000000000000000 # NOT NULL DEFAULT 1000000000000000
  @llimit = row[:llimit] || 0
  @type = row[:type] || 'AREA'

  @md5 = Digest::MD5.hexdigest(@id.to_s)

  @adjust = @parsed_meta.fetch(:adjust, '*')
  @adjustval = @parsed_meta.fetch(:adjustval, '1')
  @unit = @parsed_meta.fetch(:unit, '')
end

Instance Attribute Details

#adjustObject

Returns the value of attribute adjust.



105
106
107
# File 'lib/focuslight/graph.rb', line 105

def adjust
  @adjust
end

#adjustvalObject

Returns the value of attribute adjustval.



105
106
107
# File 'lib/focuslight/graph.rb', line 105

def adjustval
  @adjustval
end

#colorObject

Returns the value of attribute color.



102
103
104
# File 'lib/focuslight/graph.rb', line 102

def color
  @color
end

#llimitObject

Returns the value of attribute llimit.



102
103
104
# File 'lib/focuslight/graph.rb', line 102

def llimit
  @llimit
end

#md5Object (readonly)

Returns the value of attribute md5.



104
105
106
# File 'lib/focuslight/graph.rb', line 104

def md5
  @md5
end

#modeObject

Returns the value of attribute mode.



102
103
104
# File 'lib/focuslight/graph.rb', line 102

def mode
  @mode
end

#typeObject

Returns the value of attribute type.



102
103
104
# File 'lib/focuslight/graph.rb', line 102

def type
  @type
end

#ulimitObject

Returns the value of attribute ulimit.



102
103
104
# File 'lib/focuslight/graph.rb', line 102

def ulimit
  @ulimit
end

#unitObject

Returns the value of attribute unit.



105
106
107
# File 'lib/focuslight/graph.rb', line 105

def unit
  @unit
end

Class Method Details

.meta_clean(args = {}) ⇒ Object



160
161
162
163
164
165
# File 'lib/focuslight/graph.rb', line 160

def self.meta_clean(args={})
  args.delete_if do |k,v|
    %w(id service_name section_name graph_name number
       description sort mode color ulimit llimit type).include?(k.to_s)
  end
end

Instance Method Details

#complex?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/focuslight/graph.rb', line 136

def complex?
  false
end

#to_hashObject



123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/focuslight/graph.rb', line 123

def to_hash
  simple = {
    mode: @mode, color: @color,
    ulimit: @ulimit, llimit: @llimit,
    type: @type,
    adjust: @adjust, adjustval: @adjustval, unit: @unit,
    complex: false,
    md5: @md5, meta: @meta,
  }
  hash = super
  hash.merge(simple)
end

#update(args = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/focuslight/graph.rb', line 140

def update(args={})
  meta = @parsed_meta.dup
  args.each do |k, v|
    case k.to_sym
    when :number then @number = v
    when :description then @description = v
    when :sort then @sort = v
    when :mode then @mode = v
    when :color then @color = v
    when :ulimit then @ulimit = v
    when :llimit then @llimit = v
    when :type then @type = v
    else
      meta[k.to_sym] = v
    end
  end
  @parsed_meta = self.class.meta_clean(@parsed_meta.merge(meta))
  @meta = @parsed_meta.to_json
end