Class: Metz::TemplateRubyExtractor::Cursor

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#offsetObject (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

Returns:

  • (Boolean)


131
132
133
# File 'lib/metz/template_ruby_extractor.rb', line 131

def done?
  @index >= @lines.size
end

#lineObject



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