Class: Lib::DHCP::Options
- Inherits:
-
Object
- Object
- Lib::DHCP::Options
- Extended by:
- Forwardable
- Defined in:
- lib/lib/dhcp/options.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #[]=(index, option) ⇒ Object
- #add(option) ⇒ Object (also: #<<)
- #del(oid) ⇒ Object
-
#initialize(*options) ⇒ Options
constructor
A new instance of Options.
- #pack ⇒ Object
- #select(oid) ⇒ Object
Constructor Details
#initialize(*options) ⇒ Options
17 18 19 20 |
# File 'lib/lib/dhcp/options.rb', line 17 def initialize(*) = [] .each { |option| self.add option } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/lib/dhcp/options.rb', line 11 def end |
Class Method Details
.unpack(packet) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/lib/dhcp/options.rb', line 56 def self.unpack(packet) size = packet.size offset = 0 = self.new while offset < size payload = packet.unpack("@#{offset}a*").first option = Lib::DHCP::Option.unpack(payload) << option break if option.oid == Lib::DHCP::Option::END_OPTION offset += (option.len.to_i + 2) #(option.oid == 0 or option.oid == 255) ? offset += (option.len.to_i + 1) : offset += (option.len.to_i + 2) end end |
Instance Method Details
#[]=(index, option) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/lib/dhcp/options.rb', line 36 def []=(index, option) if option.is_a? Array [index] = eval("Lib::DHCP::Option#{option[0]}").new(option[1]) elsif option.is_a? Option [index] = option else << Lib::DHCP::Option.unpack(option) end end |
#add(option) ⇒ Object Also known as: <<
26 27 28 29 30 31 32 33 34 |
# File 'lib/lib/dhcp/options.rb', line 26 def add(option) if option.is_a? Array << eval("Lib::DHCP::Option#{option[0]}").new(option[1]) elsif option.is_a? Option << option else << Lib::DHCP::Option.unpack(option) end end |
#del(oid) ⇒ Object
50 51 52 |
# File 'lib/lib/dhcp/options.rb', line 50 def del(oid) .delete_if{|option| option.oid.to_i == oid.to_i} end |
#pack ⇒ Object
22 23 24 |
# File 'lib/lib/dhcp/options.rb', line 22 def pack self.map{|option| option.pack}.join('') end |
#select(oid) ⇒ Object
46 47 48 |
# File 'lib/lib/dhcp/options.rb', line 46 def select(oid) .select {|option| option.oid.to_i == oid.to_i} end |