Class: PacketGen::Header::Base::Bindings Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/packetgen/header/base.rb,
lib/packetgen/header/base.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class to handle header associations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(op) ⇒ Bindings

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Bindings.

Parameters:

  • op (:or, :and)


54
55
56
57
# File 'lib/packetgen/header/base.rb', line 54

def initialize(op)
  @op = op
  @bindings = []
end

Instance Attribute Details

#bindingsArray<Binding>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



51
52
53
# File 'lib/packetgen/header/base.rb', line 51

def bindings
  @bindings
end

#op:or, :and

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

op type

Returns:

  • (:or, :and)


49
50
51
# File 'lib/packetgen/header/base.rb', line 49

def op
  @op
end

Instance Method Details

#<<(arg) ⇒ Bindings

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns self.

Parameters:

  • arg (Object)

Returns:



61
62
63
# File 'lib/packetgen/header/base.rb', line 61

def <<(arg)
  @bindings << arg
end

#check?(fields) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check fields responds to set of bindings

Parameters:

Returns:

  • (Boolean)


86
87
88
89
90
91
92
93
# File 'lib/packetgen/header/base.rb', line 86

def check?(fields)
  case @op
  when :or
    empty? || @bindings.any? { |binding| binding.check?(fields) }
  when :and
    @bindings.all? { |binding| binding.check?(fields) }
  end
end

#eachvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

each iterator



67
68
69
# File 'lib/packetgen/header/base.rb', line 67

def each
  @bindings.each { |b| yield b }
end

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


72
73
74
# File 'lib/packetgen/header/base.rb', line 72

def empty?
  @bindings.empty?
end

#set(fields) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Set fields to bindings value

Parameters:



98
99
100
# File 'lib/packetgen/header/base.rb', line 98

def set(fields)
  @bindings.each { |b| b.set fields }
end

#to_hHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash)


77
78
79
80
81
# File 'lib/packetgen/header/base.rb', line 77

def to_h
  hsh = {}
  each { |b| hsh[b.key] = b.value }
  hsh
end