Class: Crapshoot::Scanner

Inherits:
Object
  • Object
show all
Defined in:
lib/crapshoot/scanner.rb

Overview

Turns a string into an array of tokens.

Instance Method Summary collapse

Constructor Details

#initializeScanner

Returns a new instance of Scanner.



9
10
11
# File 'lib/crapshoot/scanner.rb', line 9

def initialize
  @parser = Parser::Scan.new
end

Instance Method Details

#inspect_errorsObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/crapshoot/scanner.rb', line 28

def inspect_errors
  return 'No error' if successful?
  backtrace = @exception.backtrace
  filtered_backtrace = []
  backtrace.each do |i|
    break if i.include? __FILE__
    filtered_backtrace << i
  end
  return "#{ @exception.message } at #{ filtered_backtrace.join("\n")}"
end

#parse(line) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/crapshoot/scanner.rb', line 13

def parse(line)
  @line = line
  begin
    @result = @parser.parse @line
    return @result
  rescue => e
    @exception = e
    return nil
  end
end

#successful?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/crapshoot/scanner.rb', line 24

def successful?
  @result
end