Class: BinaryParser::LoopList
- Inherits:
-
Object
- Object
- BinaryParser::LoopList
- Includes:
- Enumerable
- Defined in:
- lib/loop_list.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#content_description ⇒ Object
String that describes this object.
- #each(&block) ⇒ Object
-
#initialize(definition, abstract_binary, parent_scope) ⇒ LoopList
constructor
A new instance of LoopList.
-
#show(recursively = false, out = STDOUT, depth = 0) ⇒ Object
Print all elements’ information.
- #size ⇒ Object
Constructor Details
#initialize(definition, abstract_binary, parent_scope) ⇒ LoopList
Returns a new instance of LoopList.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/loop_list.rb', line 5 def initialize(definition, abstract_binary, parent_scope) list, rest_binary = [], abstract_binary while rest_binary.bit_length > 0 scope = Scope.new(definition.structure, rest_binary, parent_scope) if scope.eval_entire_bit_length == 0 raise ParsingError, "0 bit-length repetition happens. This means infinite loop." end rest_binary = rest_binary.sub(:bit_index => scope.eval_entire_bit_length) list << NamelessTemplate.new(scope) end @list = list end |
Instance Method Details
#[](index) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/loop_list.rb', line 22 def [](index) unless @list[index] raise BadManipulationError, "Index is out of bounds. List size is #{@list.size}." + "You accessed list[#{index}]." end return @list[index] end |
#content_description ⇒ Object
String that describes this object.
35 36 37 |
# File 'lib/loop_list.rb', line 35 def content_description "list with #{size} elements" end |
#each(&block) ⇒ Object
18 19 20 |
# File 'lib/loop_list.rb', line 18 def each(&block) @list.each(&block) end |
#show(recursively = false, out = STDOUT, depth = 0) ⇒ Object
Print all elements’ information. Args:
recursively => Whether print recursively or not. Default is false.
out => Print target. Default is STDOUT.
43 44 45 46 47 48 49 |
# File 'lib/loop_list.rb', line 43 def show(recursively=false, out=STDOUT, depth=0) #out.puts " " * (depth * 2) + "*** LIST with #{size} elements ***" @list.each_with_index do |element, i| out.puts sprintf(" " * (depth * 2) + "%-5s", "[#{i}]") element.show(true, out, depth + 1) if recursively end end |
#size ⇒ Object
30 31 32 |
# File 'lib/loop_list.rb', line 30 def size return @list.size end |