Class: Myasorubka::AOT::Dictionary::Section
- Inherits:
-
Object
- Object
- Myasorubka::AOT::Dictionary::Section
- Includes:
- Enumerable
- Defined in:
- lib/myasorubka/aot/dictionary.rb
Overview
MRD file section handling helper class.
Each section is a set of records, one per line. The number of all records of the section is written in the very beginning of the section ata separate line.
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#[](id) ⇒ Object
:nodoc:.
-
#each(&block) ⇒ Object
:nodoc:.
-
#initialize(lines, offset, &block) ⇒ Section
constructor
:nodoc:.
-
#inspect ⇒ Object
:nodoc:.
Constructor Details
#initialize(lines, offset, &block) ⇒ Section
:nodoc:
43 44 45 46 47 |
# File 'lib/myasorubka/aot/dictionary.rb', line 43 def initialize(lines, offset, &block) @lines, @offset = lines, offset @length = lines[offset].strip.to_i @parser = block || proc { |s| s } end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
40 41 42 |
# File 'lib/myasorubka/aot/dictionary.rb', line 40 def length @length end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
40 41 42 |
# File 'lib/myasorubka/aot/dictionary.rb', line 40 def lines @lines end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
40 41 42 |
# File 'lib/myasorubka/aot/dictionary.rb', line 40 def offset @offset end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
40 41 42 |
# File 'lib/myasorubka/aot/dictionary.rb', line 40 def parser @parser end |
Instance Method Details
#[](id) ⇒ Object
:nodoc:
50 51 52 53 54 55 56 57 58 |
# File 'lib/myasorubka/aot/dictionary.rb', line 50 def [] id if id < 0 or id >= length raise ArgumentError, 'invalid id=%d when offset=%d and length=%d' % [id, offset, length] end parser.call(lines[offset + 1 + id].strip) end |
#each(&block) ⇒ Object
:nodoc:
61 62 63 |
# File 'lib/myasorubka/aot/dictionary.rb', line 61 def each(&block) length.times { |id| block.call self[id] } end |
#inspect ⇒ Object
:nodoc:
66 67 68 |
# File 'lib/myasorubka/aot/dictionary.rb', line 66 def inspect '#<%s offset=%d length=%d>' % [self.class.name, offset, length] end |