Class: Plistr::Document

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Defined in:
lib/plistr.rb

Constant Summary collapse

VALUES =
%w(string real integer date data key)
BOOLEANS =
%w(true false)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#characters(string) ⇒ Object



31
32
33
# File 'lib/plistr.rb', line 31

def characters(string)
  @text.concat string
end

#end_element(name) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/plistr.rb', line 35

def end_element(name)
  return unless value = @stack.pop

  if value.is_a?(Value)
    value.text.concat @text.strip
  end
  @text = ""

  if @stack.last.is_a?(Struct)
    @stack.last.push value
  elsif @stack.empty?
    @value = value.parse
  end
end

#start_documentObject



12
13
14
15
# File 'lib/plistr.rb', line 12

def start_document
  @stack = []
  @text = ""
end

#start_element(name, attributes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/plistr.rb', line 17

def start_element(name, attributes)
  return if name == "plist"

  if VALUES.include?(name)
    @stack.push Value.new(name)
  elsif BOOLEANS.include?(name)
    @stack.push Boolean.new(name)
  elsif name == "array"
    @stack.push Array.new
  elsif name == "dict"
    @stack.push Dict.new
  end
end