Class: Lib::BOOTP::Packet::HardwareAddressType

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/lib/bootp/packet/hardware_address_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(htype = 1) ⇒ HardwareAddressType

Returns a new instance of HardwareAddressType.

Raises:

  • (ArgumentError)


18
19
20
21
# File 'lib/lib/bootp/packet/hardware_address_type.rb', line 18

def initialize(htype=1)
  @htype = htype.is_a?(Hash) ? htype.transform_keys(&:to_sym)[:code].to_i : htype
  raise ArgumentError, "Hardware address type out of range : #{@htype}" unless (0..12).include? @htype
end

Class Method Details

.unpack(htype) ⇒ Object



82
83
84
# File 'lib/lib/bootp/packet/hardware_address_type.rb', line 82

def self.unpack(htype)
  self.new htype.unpack('C').first
end

Instance Method Details

#<=>(other) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/lib/bootp/packet/hardware_address_type.rb', line 67

def <=>(other)
  case other
    when String
      self.to_s <=> other
    when Integer
      self.to_i <=> other
    else
      self.to_i <=> other.to_i
  end
end

#packObject



78
79
80
# File 'lib/lib/bootp/packet/hardware_address_type.rb', line 78

def pack
  [@htype.to_i].pack('C')
end

#to_hObject



60
61
62
63
64
65
# File 'lib/lib/bootp/packet/hardware_address_type.rb', line 60

def to_h
  {
    code: @htype.to_s,
    name: self.to_s
  }
end

#to_json(*params) ⇒ Object



56
57
58
# File 'lib/lib/bootp/packet/hardware_address_type.rb', line 56

def to_json(*params)
  self.to_h.to_json
end

#to_sObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/lib/bootp/packet/hardware_address_type.rb', line 23

def to_s
  case @htype
    when 0
      'Lease Query'
    when 1
      'Ethernet (10Mb)'
    when 2
      'Experimental Ethernet (3Mb)'
    when 3
      'Amateur Radio AX.25'
    when 4
      'Proteon ProNET Token Ring'
    when 5
      'Chaos'
    when 6
      'IEEE 802 Networks'
    when 7
      'ARCNET'
    when 8
      'Hyperchannel'
    when 9
      'Lanstar'
    when 10
      'Autonet Short Address'
    when 11
      'LocalTalk'
    when 12
      'LocalNet (IBM PCNet or SYTEK LocalNET)'
    else
      raise ArgumentError, "Hardware address type out of range : #{@htype}"
  end
end