Class: Munin::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/munin.rb

Constant Summary collapse

DATA_SOURCE_ATTRIBUTES =
%w{ label cdef draw graph extinfo max min negative type warning critical colour skipdraw sum stack line }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Field

Returns a new instance of Field.



176
177
178
179
180
# File 'lib/munin.rb', line 176

def initialize(name, options = {})
  @name, @options = name.to_s, options

  @options[:label] ||= default_label(name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



174
175
176
# File 'lib/munin.rb', line 174

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



174
175
176
# File 'lib/munin.rb', line 174

def options
  @options
end

Instance Method Details

#==(other) ⇒ Object



209
210
211
# File 'lib/munin.rb', line 209

def ==(other)
  other and name == other.name and options == other.options
end

#configObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/munin.rb', line 192

def config
  DATA_SOURCE_ATTRIBUTES.inject({}) do |config, attribute|
    attribute = attribute.to_sym
    attribute_value = @options[attribute]

    unless attribute_value.nil?
      case attribute
        when :type
          attribute_value = attribute_value.to_s.upcase
      end
      config["#{name}.#{attribute}"] = attribute_value
    end

    config
  end
end

#default_label(name) ⇒ Object



182
183
184
# File 'lib/munin.rb', line 182

def default_label(name)
  name.to_s.gsub('_',' ')
end

#option(key) ⇒ Object



186
187
188
# File 'lib/munin.rb', line 186

def option(key)
  @options[key]
end