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)


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

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:



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

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)


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

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



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

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)


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

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



111
112
113
114
115
# File 'lib/packetgen/header/base.rb', line 111

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)


118
119
120
# File 'lib/packetgen/header/base.rb', line 118

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.



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

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:



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

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)


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

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