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(operator) ⇒ 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:

  • operator (:or, :and, :newstyle)


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

def initialize(operator)
  @op = operator
  @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:



85
86
87
# File 'lib/packetgen/header/base.rb', line 85

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)


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

def op
  @op
end

Instance Method Details

#<<(arg) ⇒ OldBindings

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:

  • (OldBindings)

    self



99
100
101
102
103
104
105
# File 'lib/packetgen/header/base.rb', line 99

def <<(arg)
  if op == :newstyle
    @bindings.last << arg
  else
    @bindings << arg
  end
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)


136
137
138
139
140
141
142
143
144
145
# File 'lib/packetgen/header/base.rb', line 136

def check?(fields)
  case @op
  when :or
    empty? || @bindings.any? { |binding| binding.check?(fields) }
  when :and
    @bindings.all? { |binding| binding.check?(fields) }
  when :newstyle
    @bindings.any? { |group| group.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



109
110
111
112
113
# File 'lib/packetgen/header/base.rb', line 109

def each
  @bindings.each do |b|
    yield b
  end
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)


116
117
118
# File 'lib/packetgen/header/base.rb', line 116

def empty?
  @bindings.empty?
end

#new_setObject

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.



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

def new_set
  @bindings << [] if @op == :newstyle
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:



150
151
152
153
154
155
156
157
# File 'lib/packetgen/header/base.rb', line 150

def set(fields)
  case @bindings.first
  when Array
    @bindings.first.each { |b| b.set fields }
  else
    @bindings.each { |b| b.set fields }
  end
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)


121
122
123
124
125
126
127
128
129
130
131
# File 'lib/packetgen/header/base.rb', line 121

def to_h
  hsh = {}
  each do |b|
    if b.is_a? Array
      b.each { |sb| hsh[sb.key] = sb.value }
    else
      hsh[b.key] = b.value
    end
  end
  hsh
end