Class: Stencil::Template::DocumentScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/stencil/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string, file = "", line = 1, column = 1) ⇒ DocumentScanner

Returns a new instance of DocumentScanner.



172
173
174
175
176
177
# File 'lib/stencil/template.rb', line 172

def initialize(string, file="", line=1, column=1)
  @file = file
  @begin_line, @begin_column = line,column
  @end_line, @end_column = line,column
  @scanner = StringScanner.new(string)
end

Instance Attribute Details

#colObject

Returns the value of attribute col.



179
180
181
# File 'lib/stencil/template.rb', line 179

def col
  @col
end

#fileObject

Returns the value of attribute file.



179
180
181
# File 'lib/stencil/template.rb', line 179

def file
  @file
end

#lineObject

Returns the value of attribute line.



179
180
181
# File 'lib/stencil/template.rb', line 179

def line
  @line
end

Instance Method Details

#locationObject



205
206
207
# File 'lib/stencil/template.rb', line 205

def location
  Directive::Source.new(@file, @begin_line, @begin_column)
end

#restObject



197
198
199
# File 'lib/stencil/template.rb', line 197

def rest
  @scanner.rest
end

#rest?Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/stencil/template.rb', line 201

def rest?
  @scanner.rest?
end

#scan(pattern) ⇒ Object



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/stencil/template.rb', line 181

def scan(pattern)
  result = @scanner.scan(pattern)
  return nil if result.nil?

  lines = result.split("\n")
  @begin_line = @end_line
  @begin_column = @end_column
  if lines.length > 1
    @end_line += lines.length - 1
    @end_column = lines.last.length + 1
  else
    @end_column += result.length
  end
  return result
end