Class: Metz::TemplateRubyExtractor::Cursor
- Inherits:
-
Object
- Object
- Metz::TemplateRubyExtractor::Cursor
- Defined in:
- lib/metz/template_ruby_extractor.rb
Overview
Tracks the running byte offset and line index while walking a template.
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
Instance Method Summary collapse
- #advance(count) ⇒ Object
- #done? ⇒ Boolean
-
#initialize(lines) ⇒ Cursor
constructor
A new instance of Cursor.
- #line ⇒ Object
- #peek(lookahead) ⇒ Object
Constructor Details
#initialize(lines) ⇒ Cursor
Returns a new instance of Cursor.
123 124 125 126 127 |
# File 'lib/metz/template_ruby_extractor.rb', line 123 def initialize(lines) @lines = lines @index = 0 @offset = 0 end |
Instance Attribute Details
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
129 130 131 |
# File 'lib/metz/template_ruby_extractor.rb', line 129 def offset @offset end |
Instance Method Details
#advance(count) ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/metz/template_ruby_extractor.rb', line 143 def advance(count) count.times do break if done? @offset += @lines[@index].length @index += 1 end end |
#done? ⇒ Boolean
131 132 133 |
# File 'lib/metz/template_ruby_extractor.rb', line 131 def done? @index >= @lines.size end |
#line ⇒ Object
135 136 137 |
# File 'lib/metz/template_ruby_extractor.rb', line 135 def line @lines[@index] end |
#peek(lookahead) ⇒ Object
139 140 141 |
# File 'lib/metz/template_ruby_extractor.rb', line 139 def peek(lookahead) @lines[@index + lookahead] end |