Class: PacketGen::Header::Base::Bindings Private
- Inherits:
-
Object
- Object
- PacketGen::Header::Base::Bindings
- 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
- #bindings ⇒ Array<Binding> private
-
#op ⇒ :or, :and
private
op type.
Instance Method Summary collapse
-
#<<(arg) ⇒ OldBindings
private
Self.
-
#check?(fields) ⇒ Boolean
private
Check
fieldsresponds to set of bindings. -
#each ⇒ void
private
each iterator.
- #empty? ⇒ Boolean private
-
#initialize(operator) ⇒ Bindings
constructor
private
A new instance of Bindings.
- #new_set ⇒ Object private
-
#set(fields) ⇒ void
private
Set
fieldsto bindings value. - #to_h ⇒ Hash private
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.
88 89 90 91 |
# File 'lib/packetgen/header/base.rb', line 88 def initialize(operator) @op = operator @bindings = [] end |
Instance Attribute Details
#bindings ⇒ Array<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.
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
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.
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
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 |
#each ⇒ 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.
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.
116 117 118 |
# File 'lib/packetgen/header/base.rb', line 116 def empty? @bindings.empty? end |
#new_set ⇒ Object
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
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_h ⇒ Hash
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.
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 |