Sha256: fe9c893adf002df4a941104242208d5c88a7593956e6a191727c67ee1af72c86

Contents?: true

Size: 975 Bytes

Versions: 5

Compression:

Stored size: 975 Bytes

Contents

module Radiustar

  class VendorCollection < Array

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

    def add(id, name)
      @collection[name] ||= Vendor.new(name, id)
      @revcollection[id.to_i] ||= @collection[name]
      self << @collection[name]
    end

    def find_by_name(name)
      @collection[name]
    end

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

  end

  class Vendor

    include Radiustar

    attr_reader :name, :id

    def initialize(name, id)
      @name = name
      @id = id
      @attributes = AttributesCollection.new self
    end

    def add_attribute(name, id, type)
      @attributes.add(name, id, type)
    end

    def find_attribute_by_name(name)
      @attributes.find_by_name(name)
    end

    def find_attribute_by_id(id)
      @attributes.find_by_id(id.to_i)
    end

    def has_attributes?
      !@attributes.empty?
    end

    def attributes
      @attributes
    end

  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
radiustar-0.0.8 lib/radiustar/vendor.rb
radiustar-0.0.7 lib/radiustar/vendor.rb
radiustar-0.0.6 lib/radiustar/vendor.rb
radiustar-0.0.5 lib/radiustar/vendor.rb
dguerri-radiustar-0.1.0 lib/radiustar/vendor.rb