Class: Plist::Listener

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeListener

Returns a new instance of Listener.



42
43
44
45
# File 'lib/plist/parser.rb', line 42

def initialize
  @result = nil
  @open   = []
end

Instance Attribute Details

#openObject

include REXML::StreamListener



40
41
42
# File 'lib/plist/parser.rb', line 40

def open
  @open
end

#resultObject

include REXML::StreamListener



40
41
42
# File 'lib/plist/parser.rb', line 40

def result
  @result
end

Instance Method Details

#tag_end(name) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/plist/parser.rb', line 58

def tag_end(name)
  last = @open.pop
  if @open.empty?
    @result = last.to_ruby
  else
    @open.last.children.push last
  end
end

#tag_start(name, attributes) ⇒ Object



47
48
49
# File 'lib/plist/parser.rb', line 47

def tag_start(name, attributes)
  @open.push PTag.mappings[name].new
end

#text(contents) ⇒ Object



51
52
53
54
55
56
# File 'lib/plist/parser.rb', line 51

def text(contents)
  if @open.last
    @open.last.text ||= ''
    @open.last.text.concat(contents)
  end
end