class FFWD::Plugin::Collectd::TypesDB
A minimal implementation of a reader for collectd’s types.db
Public Class Methods
new(database)
click to toggle source
# File lib/ffwd/plugin/collectd/types_db.rb, line 21 def initialize database @database = database end
open(path)
click to toggle source
# File lib/ffwd/plugin/collectd/types_db.rb, line 33 def self.open path return nil unless File.file? path database = {} File.open(path) do |f| f.readlines.each do |line| next if line.start_with? "#" parts = line.split(/[\t ]+/, 2) next unless parts.size == 2 key, value_specs = parts value_specs = value_specs.split(",").map(&:strip) value_specs = value_specs.map{|s| s.split(':')} database[key] = value_specs end end new database end
Public Instance Methods
get_name(key, i)
click to toggle source
# File lib/ffwd/plugin/collectd/types_db.rb, line 25 def get_name key, i if entry = @database[key] and spec = entry[i] return spec[0] end return i.to_s end