Class: Stencil::Template::DocumentScanner
- Inherits:
-
Object
- Object
- Stencil::Template::DocumentScanner
- Defined in:
- lib/stencil/template.rb
Instance Attribute Summary collapse
-
#col ⇒ Object
Returns the value of attribute col.
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
Instance Method Summary collapse
-
#initialize(string, file = "", line = 1, column = 1) ⇒ DocumentScanner
constructor
A new instance of DocumentScanner.
- #location ⇒ Object
- #rest ⇒ Object
- #rest? ⇒ Boolean
- #scan(pattern) ⇒ Object
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
#col ⇒ Object
Returns the value of attribute col.
179 180 181 |
# File 'lib/stencil/template.rb', line 179 def col @col end |
#file ⇒ Object
Returns the value of attribute file.
179 180 181 |
# File 'lib/stencil/template.rb', line 179 def file @file end |
#line ⇒ Object
Returns the value of attribute line.
179 180 181 |
# File 'lib/stencil/template.rb', line 179 def line @line end |
Instance Method Details
#location ⇒ Object
205 206 207 |
# File 'lib/stencil/template.rb', line 205 def location Directive::Source.new(@file, @begin_line, @begin_column) end |
#rest ⇒ Object
197 198 199 |
# File 'lib/stencil/template.rb', line 197 def rest @scanner.rest end |
#rest? ⇒ 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 |