class Speculate::Parser
Constants
- AROUND_END_RGX
- AROUND_PLACEHOLDER_RGX
- AROUND_START_RGX
- Error
- SPECULATION_END_RGX
- SPECULATION_START_RGX
Attributes
state[R]
stream[R]
Public Class Methods
new(speculation)
click to toggle source
# File lib/speculate/parser.rb, line 21 def initialize speculation @stream = speculation .each_line(chomp: true) .lazy end
Public Instance Methods
parse()
click to toggle source
# File lib/speculate/parser.rb, line 12 def parse @state = :outer _parse before + lines + after end
Private Instance Methods
_parse()
click to toggle source
_parse_after(line)
click to toggle source
# File lib/speculate/parser.rb, line 61 def _parse_after line case line when AROUND_END_RGX @state = :outer else after << line end end
_parse_before(line)
click to toggle source
# File lib/speculate/parser.rb, line 70 def _parse_before line case line when AROUND_PLACEHOLDER_RGX @state = :after when AROUND_END_RGX @state = :outer else before << line end end
_parse_inner(line)
click to toggle source
# File lib/speculate/parser.rb, line 81 def _parse_inner line if SPECULATION_END_RGX =~ line @state = :outer else lines << line end end
_parse_outer(line)
click to toggle source
# File lib/speculate/parser.rb, line 89 def _parse_outer line case line when AROUND_START_RGX @state = :before when SPECULATION_START_RGX @state = :inner end end
after()
click to toggle source
before()
click to toggle source
# File lib/speculate/parser.rb, line 34 def before @__before__ ||= [] end
lines()
click to toggle source
# File lib/speculate/parser.rb, line 37 def lines @__lines__ ||= [] end