Class: Plist::Listener

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Listener

Returns a new instance of Listener.



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

def initialize(options={})
  @result = nil
  @open   = []
  @options = { :marshal => true }.merge(options).freeze
end

Instance Attribute Details

#openObject

include REXML::StreamListener



45
46
47
# File 'lib/plist/parser.rb', line 45

def open
  @open
end

#resultObject

include REXML::StreamListener



45
46
47
# File 'lib/plist/parser.rb', line 45

def result
  @result
end

Instance Method Details

#tag_end(name) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/plist/parser.rb', line 64

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



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

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

#text(contents) ⇒ Object



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

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