Class: Scripref::Parser

Inherits:
Object
  • Object
show all
Includes:
BasicMethods
Defined in:
lib/scripref/parser.rb

Constant Summary

Constants included from BasicMethods

BasicMethods::NUMBER_RE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BasicMethods

#book_re, #chapter_re, #each_bookname, #verse_re

Constructor Details

#initialize(*mods) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • mods —

    one or more modules to include



16
17
18
19
# File 'lib/scripref/parser.rb', line 16

def initialize *mods
  @mods = mods
  mods.each {|m| extend m}
end

Instance Attribute Details

#error ⇒ Object (readonly)

Returns the value of attribute error.



11
12
13
# File 'lib/scripref/parser.rb', line 11

def error
  @error
end

Instance Method Details

#format_error ⇒ Object



30
31
32
33
34
35
36
# File 'lib/scripref/parser.rb', line 30

def format_error
  if error
    format("%s\n%s\n%s^", error, @scanner.string, ' ' * @scanner.pointer)
  else
    ''
  end
end

#inspect ⇒ Object



38
39
40
# File 'lib/scripref/parser.rb', line 38

def inspect
  "#<#{self.class} #{@mods.inspect}>"
end

#parse(str) ⇒ Object Also known as: <<

Parsing a string of a scripture reference

Parameters:

  • str —

    string to parse



23
24
25
26
27
28
# File 'lib/scripref/parser.rb', line 23

def parse str
  @scanner = StringScanner.new(str)
  @result = []
  @error = nil
  start
end