saxaphone 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,8 @@ module Saxaphone
18
18
  end
19
19
 
20
20
  def start_element(name, attributes = [])
21
- new_element = element_stack.empty? ? root_element_class.new(name) : element_stack.last.new_element(name)
21
+ element_class = element_stack.empty? ? root_element_class : element_stack.last.element_for(name)
22
+ new_element = element_class.new(name, '', attributes)
22
23
  element_stack << new_element
23
24
  end
24
25
 
@@ -28,10 +28,6 @@ module Saxaphone
28
28
  element_handlers[element_name] = ElementHandler.new(class_name, block)
29
29
  end
30
30
 
31
- def has_attributes(attribute_names)
32
- raise 'not implemented'
33
- end
34
-
35
31
  def element_handlers
36
32
  @element_handlers ||= {}
37
33
  end
@@ -42,10 +38,10 @@ module Saxaphone
42
38
  end
43
39
 
44
40
  attr_accessor :name, :content, :attributes
45
- def initialize(name = '', content = '')
41
+ def initialize(name = '', content = '', attribute_array = [])
46
42
  self.name = name
47
43
  self.content = content
48
- self.attributes = {}
44
+ self.attributes = Hash[attribute_array]
49
45
  setup
50
46
  end
51
47
 
@@ -58,13 +54,13 @@ module Saxaphone
58
54
  end
59
55
  end
60
56
 
61
- def new_element(element_name)
57
+ def element_for(element_name)
62
58
  if element_handler = self.class.element_handlers[element_name]
63
- klass = Saxaphone::Util.constantize(element_handler.class_name)
59
+ Saxaphone::Util.constantize(element_handler.class_name)
64
60
  else
65
- klass = Saxaphone::Element
61
+ Saxaphone::Element
66
62
  end
67
- klass.new(element_name)
63
+
68
64
  end
69
65
 
70
66
  def append_content(string)
data/test/element_test.rb CHANGED
@@ -16,6 +16,13 @@ class Saxaphone::ElementTest < MiniTest::Spec
16
16
  assert_equal 'hola', element.setup_attr
17
17
  end
18
18
 
19
+ def test_initialize
20
+ element = Saxaphone::Element.new('foo', 'bar', [['a', 'b']])
21
+ assert_equal 'foo', element.name
22
+ assert_equal 'bar', element.content
23
+ assert_equal({'a' => 'b'}, element.attributes)
24
+ end
25
+
19
26
  def test_element_attributes
20
27
  element = define_element do
21
28
  element_attributes %w(foo bar)
@@ -47,7 +54,7 @@ class Saxaphone::ElementTest < MiniTest::Spec
47
54
  end
48
55
  end
49
56
 
50
- child_element = element.new_element('omg')
57
+ child_element = element.element_for('omg').new('omg')
51
58
 
52
59
  assert_kind_of TestChildElement, child_element
53
60
  child_element.special = 'weee'
@@ -61,7 +68,7 @@ class Saxaphone::ElementTest < MiniTest::Spec
61
68
  has_element 'wtf', 'Saxaphone::ElementTest::TestChildElement'
62
69
  end
63
70
 
64
- child_element = element.new_element('wtf')
71
+ child_element = element.element_for('wtf').new('wtf')
65
72
 
66
73
  assert_kind_of TestChildElement, child_element
67
74
  element.add_element(child_element)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saxaphone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-15 00:00:00.000000000 -07:00
12
+ date: 2011-07-18 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
17
- requirement: &2157419940 !ruby/object:Gem::Requirement
17
+ requirement: &2156448040 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,7 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2157419940
25
+ version_requirements: *2156448040
26
26
  description: Use objects
27
27
  email: developer@matthewhiggins.com
28
28
  executables: []