Class: EimXML::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/eim_xml/parser.rb

Defined Under Namespace

Modules: RE

Constant Summary collapse

PARSING_MAP =
{
  'amp' => '&',
  'quot' => '"',
  'apos' => "'",
  'lt' => '<',
  'gt' => '>'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Parser

Returns a new instance of Parser.



33
34
35
36
# File 'lib/eim_xml/parser.rb', line 33

def initialize(src)
  @scanner = StringScanner.new(src)
  @scanner.scan(/\s*<\?.*?\?>\s*/)
end

Instance Attribute Details

#scannerObject (readonly)

Returns the value of attribute scanner.



15
16
17
# File 'lib/eim_xml/parser.rb', line 15

def scanner
  @scanner
end

Instance Method Details

#parseObject



38
39
40
41
42
43
44
45
46
# File 'lib/eim_xml/parser.rb', line 38

def parse
  if @scanner.scan(RE::EMPTY_ELEMENT)
    parse_empty_element
  elsif @scanner.scan(RE::START_TAG)
    parse_start_tag
  elsif @scanner.scan(RE::STRING)
    parse_string
  end
end