class Visage::Types

Attributes

types[R]

Public Class Methods

new(opts={}) click to toggle source
# File lib/visage-app/types.rb, line 7
def initialize(opts={})
  @filename = opts[:filename] || "/usr/share/collectd/types.db"
  @types    = []
  build
end

Public Instance Methods

to_json() click to toggle source
# File lib/visage-app/types.rb, line 13
def to_json
  @types.to_json
end

Private Instance Methods

build() click to toggle source
# File lib/visage-app/types.rb, line 18
def build
  file = File.new(@filename)
  file.each_line do |line|
    next if line =~ /^#/
    next if line =~ /^\s*$/
    attrs   = {}
    spec    = line.strip.split(/\t+|,\s+/)
    dataset = spec.shift
    spec.each do |source|
      parts = source.split(':')
      @types << { "dataset"    => dataset,
                  "datasource" => parts[0],
                  "type"       => parts[1],
                  "min"        => parts[2],
                  "max"        => parts[3] }
    end
  end
end