Class: CSL::Parser

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/csl/parser.rb

Overview

A relatively straightforward XML parser that parses CSL using either Nokogiri or REXML.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



27
28
29
30
31
32
33
# File 'lib/csl/parser.rb', line 27

def initialize
  require 'nokogiri'
  @parser = Parser.engines[:nokogiri]
rescue LoadError
  require 'rexml/document'
  @parser = Parser.engines[:default]
end

Class Attribute Details

.enginesObject (readonly)

Returns the value of attribute engines.



24
25
26
# File 'lib/csl/parser.rb', line 24

def engines
  @engines
end

Instance Attribute Details

#parserObject

Returns the value of attribute parser.



9
10
11
# File 'lib/csl/parser.rb', line 9

def parser
  @parser
end

Instance Method Details

#parse(*arguments) ⇒ Object



35
36
37
38
39
# File 'lib/csl/parser.rb', line 35

def parse(*arguments)
  parse!(*arguments)
rescue
  nil
end

#parse!(source, scope = Node) ⇒ Object



41
42
43
44
# File 'lib/csl/parser.rb', line 41

def parse!(source, scope = Node)
  root = parser[source].children.detect { |child| !skip?(child) }
  parse_tree root, scope
end