Class: DHCP::OptBool

Inherits:
OptFixedData show all
Defined in:
lib/dhcp/options.rb

Overview

Class for boolean DHCP options

Instance Attribute Summary

Attributes inherited from OptData

#data

Attributes inherited from Opt

#name, #opt

Instance Method Summary collapse

Methods inherited from OptFixedData

#data=, #initialize

Methods inherited from OptData

#get, #initialize, #opt_header, #set, #to_opt, #to_s

Methods inherited from Opt

#initialize, #opt_header, #to_opt, #to_s

Constructor Details

This class inherits a constructor from DHCP::OptFixedData

Instance Method Details

#bin_to_data(data) ⇒ Object



439
440
441
442
# File 'lib/dhcp/options.rb', line 439

def bin_to_data(data)
  raise "Invalid boolean binary data" if data.size != 1 || data.ord > 1
  data.ord == 0 ? false : true
end

#data_to_bin(data) ⇒ Object



434
435
436
437
# File 'lib/dhcp/options.rb', line 434

def data_to_bin(data)
  raise "Invalid boolean data #{data.class} (expected TrueClass or FalseClass)" unless data.is_a?(TrueClass) || data.is_a?(FalseClass)
  data ? 1.chr : 0.chr
end