class Rubius::Dictionary
Constants
- ATTRIBUTE
- DEFAULT_VENDOR
- VALUE
- VENDOR
Public Class Methods
new()
click to toggle source
# File lib/rubius/dictionary.rb, line 8 def initialize @dictionary = Hash.new @dictionary[DEFAULT_VENDOR] = {:name => ''} end
Public Instance Methods
attribute_id(attr_name, vendor_id = DEFAULT_VENDOR)
click to toggle source
# File lib/rubius/dictionary.rb, line 75 def attribute_id(attr_name, vendor_id = DEFAULT_VENDOR) vendor_object = @dictionary[vendor_id].reject{|k,v| !v.is_a?(Hash) || v[:name]!=attr_name} vendor_object = vendor_object.to_a if RUBY_VERSION < "1.9.2" vendor_object.flatten.first end
attribute_name(attr_id, vendor_id = DEFAULT_VENDOR)
click to toggle source
# File lib/rubius/dictionary.rb, line 67 def attribute_name(attr_id, vendor_id = DEFAULT_VENDOR) attribute(attr_id, vendor_id)[:name] rescue nil end
attribute_type(attr_id, vendor_id = DEFAULT_VENDOR)
click to toggle source
# File lib/rubius/dictionary.rb, line 71 def attribute_type(attr_id, vendor_id = DEFAULT_VENDOR) attribute(attr_id, vendor_id)[:type] rescue nil end
load(dictionary_file)
click to toggle source
# File lib/rubius/dictionary.rb, line 13 def load(dictionary_file) dict_lines = IO.readlines(dictionary_file) vendor_id = DEFAULT_VENDOR skip_until_next_vendor = false dict_lines.each do |line| next if line =~ /^\#/ next if (tokens = line.split(/\s+/)).empty? entry_type = tokens[0].upcase case entry_type when VENDOR skip_until_next_vendor = false # If the vendor_id string is nil or empty, we should skip this entire block # until we find another VENDOR definition, also ignore all VALUEs and ATTRIBUTEs # until the next VENDOR because otherwise, they will be included in the wrong VENDOR vendor_id_str = tokens[2] if vendor_id_str.nil? || vendor_id_str.empty? skip_until_next_vendor = true next end # VENDOR id should be higher than 0, skip everything if it isn't vendor_id = vendor_id_str.to_i if vendor_id <= 0 skip_until_next_vendor = true next end vendor_name = tokens[1].strip @dictionary[vendor_id] ||= {:name => vendor_name} when ATTRIBUTE next if skip_until_next_vendor next if tokens[1].nil? || tokens[2].to_i <= 0 || tokens[3].nil? @dictionary[vendor_id][tokens[2].to_i] = {:name => tokens[1].strip, :type => tokens[3].strip} when VALUE next if skip_until_next_vendor @dictionary[vendor_id][tokens[1]] = {tokens[2].strip => tokens[3].to_i} end end rescue Errno::ENOENT raise Rubius::InvalidDictionaryError end
vendor_name(vendor_id = DEFAULT_VENDOR)
click to toggle source
# File lib/rubius/dictionary.rb, line 63 def vendor_name(vendor_id = DEFAULT_VENDOR) @dictionary[vendor_id][:name] end
vendors()
click to toggle source
# File lib/rubius/dictionary.rb, line 59 def vendors @dictionary.collect{|k,v| v[:name]}.reject{|n| n.empty?} end
Private Instance Methods
attribute(attr_id, vendor_id)
click to toggle source
# File lib/rubius/dictionary.rb, line 82 def attribute(attr_id, vendor_id) @dictionary[vendor_id][attr_id] rescue nil end