Class: LibSL::FixedBlockCollection
- Inherits:
-
Object
- Object
- LibSL::FixedBlockCollection
- Defined in:
- lib/packet.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#blocks ⇒ Object
readonly
Returns the value of attribute blocks.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #decode(data) ⇒ Object
- #each(&block) ⇒ Object
- #encode ⇒ Object
-
#initialize(size, structure) ⇒ FixedBlockCollection
constructor
A new instance of FixedBlockCollection.
- #length ⇒ Object
Constructor Details
#initialize(size, structure) ⇒ FixedBlockCollection
Returns a new instance of FixedBlockCollection.
214 215 216 217 218 |
# File 'lib/packet.rb', line 214 def initialize(size, structure) @size = size @blocks = [] @size.times{@blocks << Block.new(structure)} end |
Instance Attribute Details
#blocks ⇒ Object (readonly)
Returns the value of attribute blocks.
213 214 215 |
# File 'lib/packet.rb', line 213 def blocks @blocks end |
Instance Method Details
#[](index) ⇒ Object
224 225 226 227 |
# File 'lib/packet.rb', line 224 def [](index) throw "Index out of range: #{index} is not in [0, #{length - 1}]" if index < 0 or index >= length @blocks[index] end |
#decode(data) ⇒ Object
233 234 235 236 |
# File 'lib/packet.rb', line 233 def decode(data) @blocks.each{ |block| data = block.decode(data) } data end |
#each(&block) ⇒ Object
229 230 231 |
# File 'lib/packet.rb', line 229 def each(&block) @blocks.each{|block| yield block} end |
#encode ⇒ Object
238 239 240 241 242 |
# File 'lib/packet.rb', line 238 def encode() data = "" @blocks.each{ |block| data += block.encode } data end |
#length ⇒ Object
220 221 222 |
# File 'lib/packet.rb', line 220 def length() @size end |