Class: NRB::BeerXML::Parser

Inherits:
Object
  • Object
show all
Includes:
Inflector
Defined in:
lib/nrb/beerxml/parser.rb

Defined Under Namespace

Classes: InvalidRecordError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inflector

#camelize, #underscore

Constructor Details

#initialize(builder: Builder.new, reader: Nokogiri::XML, perform_validations: true) ⇒ Parser

Returns a new instance of Parser.



28
29
30
31
32
# File 'lib/nrb/beerxml/parser.rb', line 28

def initialize(builder: Builder.new, reader: Nokogiri::XML, perform_validations: true)
  @perform_validations = perform_validations
  @builder = builder
  @reader = reader
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



26
27
28
# File 'lib/nrb/beerxml/parser.rb', line 26

def builder
  @builder
end

#perform_validationsObject (readonly)

Returns the value of attribute perform_validations.



26
27
28
# File 'lib/nrb/beerxml/parser.rb', line 26

def perform_validations
  @perform_validations
end

#readerObject (readonly)

Returns the value of attribute reader.



26
27
28
# File 'lib/nrb/beerxml/parser.rb', line 26

def reader
  @reader
end

Instance Method Details

#parse(entry) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nrb/beerxml/parser.rb', line 35

def parse(entry)
  doc = case entry
        when IO, StringIO
          parse_xml entry
        when String
          parse_path(file: entry)
        else
          raise ArgumentError "Don't know how to parse a #{entry.class}"
        end
  parse_node doc.root
end