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.
90 91 92 93 |
# File 'lib/packetgen/header/base.rb', line 90 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.
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
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.
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
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 |
#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
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.
118 119 120 |
# File 'lib/packetgen/header/base.rb', line 118 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.
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
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_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.
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 |