Class: Norma43::Parser
- Inherits:
-
Object
- Object
- Norma43::Parser
- Defined in:
- lib/norma43/parser.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
-
#initialize(file) ⇒ Parser
constructor
Parser.new accepts a File instance or a String A InvalidFileFormatError will be raised if file isn’t in the Norma43 format.
- #result ⇒ Object
Constructor Details
#initialize(file) ⇒ Parser
Parser.new accepts a File instance or a String A InvalidFileFormatError will be raised if file isn’t in the Norma43 format
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/norma43/parser.rb', line 11 def initialize(file) @file = file validator = validate_file_format @contexts = if validator.has_document? Norma43::Utils::Contexts.new else # in theory Norma43 says that files should start with DocumentStart but # practically doesn't happen, so that we create one artificially # to avoid corner cases in the processors Norma43::Utils::Contexts.new().tap { |ctx| ctx.add Models::Document.new } end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/norma43/parser.rb', line 7 def file @file end |
Instance Method Details
#result ⇒ Object
24 25 26 |
# File 'lib/norma43/parser.rb', line 24 def result parse_lines(@contexts).result end |