Class: Dot11::Packet

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters = {}) ⇒ Packet

Returns a new instance of Packet.



18
19
20
21
22
23
24
25
26
# File 'lib/dot11/packet.rb', line 18

def initialize(parameters = {})
  if parameters.kind_of?(String)
    dissect(parameters)
  elsif parameters.kind_of?(Hash)
    parameters.each_pair do |key, value|
      send((key.to_s + "=").intern, value)
    end
  end
end

Class Method Details

.new(parameters = {}) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/dot11/packet.rb', line 8

def new(parameters = {})
  # Maybe we shouldn't do it this way, but it looks prettier
  if !parameters.kind_of?(String) && parameters.values.any? {|v| v.kind_of?(Array) || v.kind_of?(Range)}
    PacketSet.new(self, parameters)
  else
    older_new(parameters)
  end
end

.older_newObject



6
# File 'lib/dot11/packet.rb', line 6

alias older_new new

Instance Method Details

#=~(other) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/dot11/packet.rb', line 28

def =~(other)
  if other.kind_of?(Hash)
    other.each_pair do |key, value|
      return false if self.send(key) != value
    end
  
    return true
  end
end

#to_filterObject



38
39
40
41
42
43
# File 'lib/dot11/packet.rb', line 38

def to_filter
  PacketSet.new(self.class, self.instance_variables.inject({}) do |accum, var| 
    accum[var[1..-1].intern] = self.instance_variable_get(var).kind_of?(MACAddress) ? self.instance_variable_get(var).to_s : self.instance_variable_get(var).to_s
    accum
  end).to_filter
end