Class: Lab419::Config::Source
- Inherits:
-
Object
- Object
- Lab419::Config::Source
- Defined in:
- lib/lab419/config/source.rb
Overview
Source is a wrapper arround an array of lines, adding the ability to store the current line_number #line_nb and the name of the source #name. It implements a minimal interface, allowing to advance line by line via the #next method, accessing the current element via #current and testing for the end of the array via the #eos? method
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#current ⇒ Object
accesses the current element.
-
#eos? ⇒ Boolean
true iff #next has advanced over the last line.
-
#line_nb ⇒ Object
current line number, starting with 1, incremented by each call of #next, up to a maximum of the size of the underlying array.
-
#next ⇒ Object
This is the only modifier of Source, it advances to the next line of the underlying array.
- #to_debug ⇒ Object
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/lab419/config/source.rb', line 13 def name @name end |
Instance Method Details
#current ⇒ Object
accesses the current element
21 22 23 |
# File 'lib/lab419/config/source.rb', line 21 def current @lines[ @cursor ] end |
#eos? ⇒ Boolean
true iff #next has advanced over the last line
26 27 28 |
# File 'lib/lab419/config/source.rb', line 26 def eos? @lines[ @cursor ].nil? end |
#line_nb ⇒ Object
current line number, starting with 1, incremented by each call of #next, up to a maximum of the size of the underlying array.
33 34 35 |
# File 'lib/lab419/config/source.rb', line 33 def line_nb [ @cursor + 1, @lines.length ].min end |
#next ⇒ Object
This is the only modifier of Source, it advances to the next line of the underlying array. The operation is irreversible.
40 41 42 43 |
# File 'lib/lab419/config/source.rb', line 40 def next @cursor += 1 current end |
#to_debug ⇒ Object
45 46 47 |
# File 'lib/lab419/config/source.rb', line 45 def to_debug "#{@lines[@cursor-1]}:>#{current}<:#{@lines[@cursor+1]}" end |