Class: DHCP::OptData

Inherits:
Opt
  • Object
show all
Defined in:
lib/dhcp/options.rb

Overview

Class for DHCP options that contain data

Instance Attribute Summary collapse

Attributes inherited from Opt

#name, #opt

Instance Method Summary collapse

Constructor Details

#initialize(opt, name, data = nil) ⇒ OptData

Returns a new instance of OptData.



67
68
69
70
# File 'lib/dhcp/options.rb', line 67

def initialize(opt, name, data=nil)
  super(opt, name)
  @data = data.nil? ? '' : data_to_bin(data)
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



71
72
73
# File 'lib/dhcp/options.rb', line 71

def data
  @data
end

Instance Method Details

#bin_to_data(data) ⇒ Object

Override this in subclasses to interpret data



95
96
97
# File 'lib/dhcp/options.rb', line 95

def bin_to_data(data)  ## Override this in subclasses to interpret data
  data
end

#data_to_bin(data) ⇒ Object

Override this in subclasses to interpret data



91
92
93
# File 'lib/dhcp/options.rb', line 91

def data_to_bin(data)  ## Override this in subclasses to interpret data
  data
end

#getObject



87
88
89
# File 'lib/dhcp/options.rb', line 87

def get
  bin_to_data(@data)
end

#opt_headerObject



99
100
101
# File 'lib/dhcp/options.rb', line 99

def opt_header
  super + "(#{data.size})"
end

#set(data) ⇒ Object



82
83
84
85
# File 'lib/dhcp/options.rb', line 82

def set(data)
  self.data = data_to_bin(data)
  self ## Chainable
end

#to_optObject



107
108
109
# File 'lib/dhcp/options.rb', line 107

def to_opt
  super + @data.size.chr + @data
end

#to_sObject



103
104
105
# File 'lib/dhcp/options.rb', line 103

def to_s
  opt_header + "='#{bin_to_data(@data)}'"
end