Sha256: c27a1851cbc95e4ed91209a12a36634590c76084c1f88df00cfdbded082d5f20

Contents?: true

Size: 879 Bytes

Versions: 2

Compression:

Stored size: 879 Bytes

Contents

module Radiustar

  class AttributesCollection

    def initialize
      @collection = {}
      @revcollection = []
    end

    def add(name, id, type)
      @collection[name] ||= Attribute.new(name, id.to_i, type)
      @revcollection[id.to_i] ||= @collection[name]
    end

    def find_by_name(name)
      @collection[name]
    end

    def find_by_id(id)
      @revcollection[id.to_i]
    end

  end

  class Attribute

    attr_reader :name, :id, :type

    def initialize(name, id, type)
      @values = ValuesCollection.new
      @name = name
      @id = id.to_i
      @type = type
    end

    def add_value(name, id)
      @values.add(name, id.to_i)
    end

    def find_values_by_name(name)
      @values.find_by_name(name)
    end

    def find_values_by_id(id)
      @values.find_by_id(id.to_i)
    end

    def has_values?
      !@values.empty?
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
radiustar-0.0.2 lib/radiustar/dictionary/attributes.rb
radiustar-0.0.1 lib/radiustar/dictionary/attributes.rb