Class: Zerbo::Packet

Inherits:
Object
  • Object
show all
Defined in:
lib/zerbo.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, time, subtime, sequence, data) ⇒ Packet

Returns a new instance of Packet.



107
108
109
110
111
# File 'lib/zerbo.rb', line 107

def initialize(owner, time, subtime, sequence, data)
  @owner = owner
  @sequence = sequence
  @data = data
end

Class Attribute Details

.idObject

Returns the value of attribute id.



98
99
100
# File 'lib/zerbo.rb', line 98

def id
  @id
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



101
102
103
# File 'lib/zerbo.rb', line 101

def data
  @data
end

#ownerObject (readonly)

Returns the value of attribute owner.



101
102
103
# File 'lib/zerbo.rb', line 101

def owner
  @owner
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



101
102
103
# File 'lib/zerbo.rb', line 101

def sequence
  @sequence
end

#typeObject (readonly)

Returns the value of attribute type.



101
102
103
# File 'lib/zerbo.rb', line 101

def type
  @type
end

Class Method Details

.inherited(klass) ⇒ Object



93
94
95
# File 'lib/zerbo.rb', line 93

def self.inherited(klass)
  DATA_TYPE_CLASSES << klass
end

Instance Method Details

#guess_lengthObject



113
114
115
# File 'lib/zerbo.rb', line 113

def guess_length
  data.index('A')
end

#inspectObject



132
133
134
# File 'lib/zerbo.rb', line 132

def inspect
  format_inspect((to_i || data).inspect)
end

#nameObject Also known as: to_s



127
128
129
# File 'lib/zerbo.rb', line 127

def name
  self.class.name.split('::').last
end

#to_iObject



117
118
119
120
121
122
123
124
125
# File 'lib/zerbo.rb', line 117

def to_i
  if data.length == 2
    unpack('v').first
  elsif data.length == 4
    unpack('V').first
  else
    raise NotImplementedError
  end
end