Class: DHCP::OptListData

Inherits:
OptData show all
Includes:
Enumerable
Defined in:
lib/dhcp/options.rb

Overview

Class for DHCP options that contain a lists (like lists of IPs)

Direct Known Subclasses

OptListFixedData, OptRouteList, OptSubList, SubOptList

Instance Attribute Summary

Attributes inherited from OptData

#data

Attributes inherited from Opt

#name, #opt

Instance Method Summary collapse

Methods inherited from OptData

#bin_to_data, #data_to_bin, #opt_header, #to_opt

Methods inherited from Opt

#opt_header, #to_opt

Constructor Details

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

Returns a new instance of OptListData.



135
136
137
138
139
# File 'lib/dhcp/options.rb', line 135

def initialize(opt, name, data=nil)
  super(opt, name)
  @size = 0
  set(data) unless data.nil?
end

Instance Method Details

#append(item) ⇒ Object



163
164
165
166
167
# File 'lib/dhcp/options.rb', line 163

def append(item)
  @size += 1
  @data += data_to_bin(item)
  self ## Chainable
end

#data=(data) ⇒ Object



141
142
143
# File 'lib/dhcp/options.rb', line 141

def data=(data)
  set(split_data(data))
end

#eachObject



181
182
183
184
185
# File 'lib/dhcp/options.rb', line 181

def each
  split_data(@data).each do |item|
    yield item
  end
end

#getObject



145
146
147
# File 'lib/dhcp/options.rb', line 145

def get
  split_data(@data)  ## Splits and interprets binary data
end

#is_list?(list) ⇒ Boolean

Override if needed in child class

Returns:

  • (Boolean)


159
160
161
# File 'lib/dhcp/options.rb', line 159

def is_list?(list) ## Override if needed in child class
  list.is_a?(Array)
end

#set(list) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/dhcp/options.rb', line 149

def set(list)
  list = [list] unless is_list?(list)
  @data = ''
  @size = 0
  list.each do |item|
    append(item)
  end
  self ## Chainable
end

#sizeObject



173
174
175
# File 'lib/dhcp/options.rb', line 173

def size
  @size
end

#split_data(data) ⇒ Object

Override in child class to split and interpret binary data



169
170
171
# File 'lib/dhcp/options.rb', line 169

def split_data(data) ## Override in child class to split and interpret binary data
  raise "Child class #{data.class} MUST override this"
end

#to_sObject



177
178
179
# File 'lib/dhcp/options.rb', line 177

def to_s
  opt_header + '=[' + map{|x| x.to_s}.join(',') + ']'
end