Class: FFWD::Plugin::Collectd::TypesDB
- Inherits:
-
Object
- Object
- FFWD::Plugin::Collectd::TypesDB
- Defined in:
- lib/ffwd/plugin/collectd/types_db.rb
Overview
A minimal implementation of a reader for collectd’s types.db
Class Method Summary collapse
Instance Method Summary collapse
- #get_name(key, i) ⇒ Object
-
#initialize(database) ⇒ TypesDB
constructor
A new instance of TypesDB.
Constructor Details
#initialize(database) ⇒ TypesDB
Returns a new instance of TypesDB.
21 22 23 |
# File 'lib/ffwd/plugin/collectd/types_db.rb', line 21 def initialize database @database = database end |
Class Method Details
.open(path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |
Instance Method Details
#get_name(key, i) ⇒ Object
25 26 27 28 29 30 31 |
# 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 |