Class: OXM

Inherits:
Object
  • Object
show all
Defined in:
lib/oxm.rb,
lib/oxm/object.rb,
lib/oxm/version.rb,
lib/oxm/sax_handler.rb

Defined Under Namespace

Classes: Object, SaxHandler

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ OXM

Returns a new instance of OXM.

Parameters:

  • xml (IO/String)

    XML data



16
17
18
# File 'lib/oxm.rb', line 16

def initialize xml
  @xml = xml
end

Class Method Details

.from_xml(xml, loop_element, &block) ⇒ Array

Returns Array of OXM::Objects.

Parameters:

  • xml (IO/String)

    XML data

  • loop_element (String)

Returns:

  • (Array)

    Array of OXM::Objects



10
11
12
13
# File 'lib/oxm.rb', line 10

def self.from_xml xml, loop_element, &block
  oxm = OXM.new xml
  oxm.from_xml loop_element, &block
end

Instance Method Details

#errorsArray

Returns Error messages during the last from_xml call.

Returns:

  • (Array)

    Error messages during the last from_xml call



29
30
31
# File 'lib/oxm.rb', line 29

def errors
  @handler ? @handler.errors : []
end

#from_xml(loop_element, &block) ⇒ Object

Parameters:

  • loop_element (String)


21
22
23
24
25
26
# File 'lib/oxm.rb', line 21

def from_xml loop_element, &block
  return enum_for(:from_xml, loop_element, &block) unless block_given?
  @handler = OXM::SaxHandler.new(loop_element, &block)
  parser = Nokogiri::XML::SAX::Parser.new(@handler, 'UTF-8')
  parser.parse @xml
end

#warningsArray

Returns Warning messages during the last from_xml call.

Returns:

  • (Array)

    Warning messages during the last from_xml call



34
35
36
# File 'lib/oxm.rb', line 34

def warnings
  @handler ? @handler.warnings : []
end