Class: Fabulator::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/fabulator/compiler.rb

Instance Method Summary collapse

Constructor Details

#initializeCompiler

Returns a new instance of Compiler.



5
6
7
# File 'lib/fabulator/compiler.rb', line 5

def initialize
  @context = Fabulator::Expr::Context.new
end

Instance Method Details

#compile(xml) ⇒ Object

Calls the right compiler object based on the root element



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fabulator/compiler.rb', line 10

def compile(xml)
  XML.default_line_numbers = true

  doc = nil

  if xml.is_a?(String)
    doc = LibXML::XML::Document.string xml
    doc = doc.root
  elsif xml.is_a?(LibXML::XML::Document)
    doc = xml.root
  else
    doc = xml
  end

  @context.compile_structural(doc)
end