Class: Nodaire::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/nodaire/parser.rb

Direct Known Subclasses

Indental::Parser, Tablatal::Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strict, options = {}) ⇒ Parser

Returns a new instance of Parser.



10
11
12
13
14
# File 'lib/nodaire/parser.rb', line 10

def initialize(strict, options = {})
  @strict = strict
  @options = options
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/nodaire/parser.rb', line 8

def errors
  @errors
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/nodaire/parser.rb', line 8

def options
  @options
end

Instance Method Details

#oops!(message, line_num) ⇒ Object



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

def oops!(message, line_num)
  message = "#{message} on line #{line_num}" unless line_num.nil?
  errors << message
  raise Nodaire::ParserError, message if strict?
end

#option(name, default = nil) ⇒ Object



20
21
22
# File 'lib/nodaire/parser.rb', line 20

def option(name, default = nil)
  @options.fetch(name, default)
end

#strict?Boolean

Returns:

  • (Boolean)


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

def strict?
  @strict
end