Class: HWAddr::Database
- Inherits:
-
Object
- Object
- HWAddr::Database
- Includes:
- Enumerable, Singleton
- Defined in:
- lib/hwaddr/database.rb
Defined Under Namespace
Classes: Company
Class Method Summary collapse
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add(name, range, address = nil) ⇒ Object
- #each(&block) ⇒ Object
- #entries(&block) ⇒ Object
-
#initialize ⇒ Database
constructor
A new instance of Database.
Constructor Details
#initialize ⇒ Database
Returns a new instance of Database.
62 63 64 |
# File 'lib/hwaddr/database.rb', line 62 def initialize @companies = {} end |
Class Method Details
.method_missing(*args, &block) ⇒ Object
17 18 19 |
# File 'lib/hwaddr/database.rb', line 17 def self.method_missing (*args, &block) instance.__send__(*args, &block) end |
Instance Method Details
#[](name) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/hwaddr/database.rb', line 73 def [] (name) name = name.to_s if HWAddr.valid?(name) find { |c| c === name } else find { |c| c.name == name } end end |
#add(name, range, address = nil) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/hwaddr/database.rb', line 66 def add (name, range, address = nil) company = @companies[name] ||= Company.new(name) company.add(range, address) self end |
#each(&block) ⇒ Object
83 84 85 86 87 |
# File 'lib/hwaddr/database.rb', line 83 def each (&block) return to_enum unless block @companies.each_value(&block) end |
#entries(&block) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/hwaddr/database.rb', line 89 def entries (&block) return enum_for :entries unless block @companies.each {|company| company.each {|range| yield range } } end |