Class: AWS::Core::XML::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/core/xml/parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rules = {}) ⇒ Parser

Returns a new instance of Parser.

Parameters:

  • rules (Hash) (defaults to: {})

    A has of xml parsing rules. Generally rules will come from an xml grammar.



21
22
23
# File 'lib/aws/core/xml/parser.rb', line 21

def initialize rules = {}
  @rules = rules
end

Instance Attribute Details

#rulesHash (readonly)

Returns the rules for this xml parser that define how it should transform the XMl into Ruby.

Returns:

  • (Hash)

    Returns the rules for this xml parser that define how it should transform the XMl into Ruby.



27
28
29
# File 'lib/aws/core/xml/parser.rb', line 27

def rules
  @rules
end

Class Method Details

.parse(xml, rules = {}) ⇒ Hash

Returns a hash of parsed xml data.

Parameters:

  • xml (String)

    An XML document string to parse.

  • rules (Hash) (defaults to: {})

    A has of xml parsing rules. Generally rules will come from an xml grammar.

Returns:

  • (Hash)

    Returns a hash of parsed xml data.



45
46
47
# File 'lib/aws/core/xml/parser.rb', line 45

def self.parse xml, rules = {}
  self.new(rules).parse(xml)
end

Instance Method Details

#parse(xml) ⇒ Hash

Returns a hash of parsed xml data.

Parameters:

  • xml (String)

    An XML document string to parse.

Returns:

  • (Hash)

    Returns a hash of parsed xml data.



31
32
33
34
# File 'lib/aws/core/xml/parser.rb', line 31

def parse xml
  xml = '<xml/>' if xml.nil? or xml.empty?
  sax_handler.parse(xml)
end

#simulateHash

Returns a hash of mostly empty placeholder data.

Returns:

  • (Hash)

    Returns a hash of mostly empty placeholder data.



37
38
39
# File 'lib/aws/core/xml/parser.rb', line 37

def simulate
  XML::Stub.simulate(rules)
end