saxaphone 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,12 +4,14 @@ module Saxaphone
4
4
  class Document < Nokogiri::XML::SAX::Document
5
5
  class << self
6
6
  def parse(io, root_element_class)
7
- parser = Nokogiri::XML::SAX::Parser.new(new(root_element_class))
7
+ document = new(root_element_class)
8
+ parser = Nokogiri::XML::SAX::Parser.new(document)
8
9
  parser.parse(io)
10
+ document.root_element
9
11
  end
10
12
  end
11
13
 
12
- attr_accessor :element_stack, :root_element_class
14
+ attr_accessor :element_stack, :root_element_class, :root_element
13
15
  def initialize(root_element_class)
14
16
  @element_stack = []
15
17
  @root_element_class = root_element_class
@@ -22,7 +24,9 @@ module Saxaphone
22
24
 
23
25
  def end_element(name)
24
26
  ending_element = element_stack.pop
25
- unless element_stack.empty?
27
+ if element_stack.empty?
28
+ self.root_element = ending_element
29
+ else
26
30
  element_stack.last.add_element(ending_element)
27
31
  end
28
32
  end
data/test/element_test.rb CHANGED
@@ -5,30 +5,22 @@ class Saxaphone::ElementTest < MiniTest::Spec
5
5
  attr_accessor :special
6
6
  end
7
7
 
8
- class TestElement < Saxaphone::Element
9
- attr_accessor :setup_attr
10
- attr_accessor :child_special
11
- setup do
12
- self.setup_attr = 'hola'
13
- end
14
-
15
- element_attributes %w(foo bar)
16
- element_attribute 'faz', as: 'baz'
17
-
18
- has_element 'omg', 'Saxaphone::ElementTest::TestChildElement' do |element|
19
- self.child_special = element.special
8
+ def test_setup
9
+ element = define_element do
10
+ attr_accessor :setup_attr
11
+ setup do
12
+ self.setup_attr = 'hola'
13
+ end
20
14
  end
21
15
 
22
- has_element 'wtf', 'Saxaphone::ElementTest::TestChildElement'
23
- end
24
-
25
- def test_setup
26
- element = TestElement.new
27
16
  assert_equal 'hola', element.setup_attr
28
17
  end
29
18
 
30
19
  def test_element_attributes
31
- element = TestElement.new
20
+ element = define_element do
21
+ element_attributes %w(foo bar)
22
+ end
23
+
32
24
  element.add_element(Saxaphone::Element.new('foo', 'value1'))
33
25
  element.add_element(Saxaphone::Element.new('bar', 'value2'))
34
26
  element.add_element(Saxaphone::Element.new('invalid', 'value3'))
@@ -37,14 +29,24 @@ class Saxaphone::ElementTest < MiniTest::Spec
37
29
  end
38
30
 
39
31
  def test_element_attribute
40
- element = TestElement.new
32
+ element = define_element do
33
+ element_attribute 'faz', as: 'baz'
34
+ end
35
+
41
36
  element.add_element(Saxaphone::Element.new('faz', 'value'))
42
37
 
43
38
  assert_equal({'baz' => 'value'}, element.attributes)
44
39
  end
45
40
 
46
41
  def test_has_element_with_block
47
- element = TestElement.new
42
+ element = define_element do
43
+ attr_accessor :child_special
44
+
45
+ has_element 'omg', 'Saxaphone::ElementTest::TestChildElement' do |element|
46
+ self.child_special = element.special
47
+ end
48
+ end
49
+
48
50
  child_element = element.new_element('omg')
49
51
 
50
52
  assert_kind_of TestChildElement, child_element
@@ -55,11 +57,19 @@ class Saxaphone::ElementTest < MiniTest::Spec
55
57
  end
56
58
 
57
59
  def test_has_element_without_block
58
- element = TestElement.new
59
- child_element = element.new_element('omg')
60
+ element = define_element do
61
+ has_element 'wtf', 'Saxaphone::ElementTest::TestChildElement'
62
+ end
63
+
64
+ child_element = element.new_element('wtf')
60
65
 
61
66
  assert_kind_of TestChildElement, child_element
62
67
  element.add_element(child_element)
63
68
  # silence?
64
69
  end
70
+
71
+ private
72
+ def define_element(&block)
73
+ Class.new(Saxaphone::Element, &block).new
74
+ end
65
75
  end
metadata CHANGED
@@ -1,38 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: saxaphone
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
4
5
  prerelease:
5
- version: 0.2.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Matthew Higgins
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-06-01 00:00:00 -07:00
12
+ date: 2011-07-15 00:00:00.000000000 -07:00
14
13
  default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: nokogiri
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &2157419940 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
25
23
  type: :runtime
26
- version_requirements: *id001
24
+ prerelease: false
25
+ version_requirements: *2157419940
27
26
  description: Use objects
28
27
  email: developer@matthewhiggins.com
29
28
  executables: []
30
-
31
29
  extensions: []
32
-
33
- extra_rdoc_files:
30
+ extra_rdoc_files:
34
31
  - README.rdoc
35
- files:
32
+ files:
36
33
  - MIT-LICENSE
37
34
  - Rakefile
38
35
  - README.rdoc
@@ -46,30 +43,26 @@ files:
46
43
  has_rdoc: true
47
44
  homepage: http://github.com/matthuhiggins/saxaphone
48
45
  licenses: []
49
-
50
46
  post_install_message:
51
47
  rdoc_options: []
52
-
53
- require_paths:
48
+ require_paths:
54
49
  - lib
55
- required_ruby_version: !ruby/object:Gem::Requirement
50
+ required_ruby_version: !ruby/object:Gem::Requirement
56
51
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
60
55
  version: 1.9.2
61
- required_rubygems_version: !ruby/object:Gem::Requirement
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
57
  none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
66
61
  version: 1.3.5
67
62
  requirements: []
68
-
69
63
  rubyforge_project:
70
64
  rubygems_version: 1.6.2
71
65
  signing_key:
72
66
  specification_version: 3
73
67
  summary: Object Oriented SAX Parsing
74
68
  test_files: []
75
-