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

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
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)


81
82
83
84
# File 'lib/packetgen/header/base.rb', line 81

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:



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

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)


76
77
78
# File 'lib/packetgen/header/base.rb', line 76

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:



88
89
90
# File 'lib/packetgen/header/base.rb', line 88

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)


113
114
115
116
117
118
119
120
# File 'lib/packetgen/header/base.rb', line 113

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



94
95
96
# File 'lib/packetgen/header/base.rb', line 94

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)


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

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:



125
126
127
# File 'lib/packetgen/header/base.rb', line 125

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)


104
105
106
107
108
# File 'lib/packetgen/header/base.rb', line 104

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