Class: BeerXML

Inherits:
Brewser::Engine show all
Defined in:
lib/brewser/engines/beerxml.rb

Defined Under Namespace

Classes: Additive, Fermentable, FermentationSchedule, FermentationStep, Hop, MashSchedule, MashStep, Recipe, Style, WaterProfile, Yeast

Class Method Summary collapse

Class Method Details

.acceptable?(q) ⇒ Boolean

Simple test to see if this looks like XML

Returns:

  • (Boolean)


8
9
10
# File 'lib/brewser/engines/beerxml.rb', line 8

def acceptable?(q)
  Nokogiri::XML(q){|config| config.noblanks }.root ? true : false
end

.cleanup(brewser_objects) ⇒ Object

Ugly hack to deal with BeerXML oddities



27
28
29
# File 'lib/brewser/engines/beerxml.rb', line 27

def cleanup(brewser_objects)
  brewser_objects.each(&:cleanup)
end

.deserialize(string_or_io) ⇒ Object

Attempt to deserialize the data



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/brewser/engines/beerxml.rb', line 13

def deserialize(string_or_io)
  begin
    outer = Nokogiri::XML(string_or_io).root
    # We expect to find a plural of one of the models
    objects = (outer>outer.node_name.singularize).map do |inner|
      ("BeerXML::#{inner.node_name.downcase.camelcase}".constantize).from_xml(inner)
    end
    return cleanup(objects)
 # rescue
 #   raise Error, "BeerXML engine encountered an issue and can not continue"
  end
end