saxaphone 0.1.0 → 0.2.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.
- data/lib/saxaphone/element.rb +2 -2
- data/lib/saxaphone/util.rb +16 -0
- data/lib/saxaphone.rb +1 -0
- data/test/element_test.rb +16 -3
- metadata +4 -3
data/lib/saxaphone/element.rb
CHANGED
@@ -54,13 +54,13 @@ module Saxaphone
|
|
54
54
|
|
55
55
|
def add_element(element)
|
56
56
|
if element_handler = self.class.element_handlers[element.name]
|
57
|
-
instance_exec(element, &element_handler.proc)
|
57
|
+
instance_exec(element, &element_handler.proc) if element_handler.proc
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
def new_element(element_name)
|
62
62
|
if element_handler = self.class.element_handlers[element_name]
|
63
|
-
klass = element_handler.class_name
|
63
|
+
klass = Saxaphone::Util.constantize(element_handler.class_name)
|
64
64
|
else
|
65
65
|
klass = Saxaphone::Element
|
66
66
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Saxaphone
|
2
|
+
class Util
|
3
|
+
class << self
|
4
|
+
def constantize(camel_cased_word)
|
5
|
+
names = camel_cased_word.split('::')
|
6
|
+
names.shift if names.empty? || names.first.empty?
|
7
|
+
|
8
|
+
constant = Object
|
9
|
+
names.each do |name|
|
10
|
+
constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
|
11
|
+
end
|
12
|
+
constant
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/saxaphone.rb
CHANGED
data/test/element_test.rb
CHANGED
@@ -15,9 +15,11 @@ class Saxaphone::ElementTest < MiniTest::Spec
|
|
15
15
|
element_attributes %w(foo bar)
|
16
16
|
element_attribute 'faz', as: 'baz'
|
17
17
|
|
18
|
-
has_element 'omg', 'TestChildElement' do |element|
|
18
|
+
has_element 'omg', 'Saxaphone::ElementTest::TestChildElement' do |element|
|
19
19
|
self.child_special = element.special
|
20
20
|
end
|
21
|
+
|
22
|
+
has_element 'wtf', 'Saxaphone::ElementTest::TestChildElement'
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_setup
|
@@ -41,12 +43,23 @@ class Saxaphone::ElementTest < MiniTest::Spec
|
|
41
43
|
assert_equal({'baz' => 'value'}, element.attributes)
|
42
44
|
end
|
43
45
|
|
44
|
-
def
|
46
|
+
def test_has_element_with_block
|
45
47
|
element = TestElement.new
|
46
|
-
child_element =
|
48
|
+
child_element = element.new_element('omg')
|
49
|
+
|
50
|
+
assert_kind_of TestChildElement, child_element
|
47
51
|
child_element.special = 'weee'
|
48
52
|
element.add_element(child_element)
|
49
53
|
|
50
54
|
assert_equal 'weee', element.child_special
|
51
55
|
end
|
56
|
+
|
57
|
+
def test_has_element_without_block
|
58
|
+
element = TestElement.new
|
59
|
+
child_element = element.new_element('omg')
|
60
|
+
|
61
|
+
assert_kind_of TestChildElement, child_element
|
62
|
+
element.add_element(child_element)
|
63
|
+
# silence?
|
64
|
+
end
|
52
65
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: saxaphone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Matthew Higgins
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-06-01 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- lib/saxaphone/document.rb
|
40
40
|
- lib/saxaphone/element.rb
|
41
|
+
- lib/saxaphone/util.rb
|
41
42
|
- lib/saxaphone.rb
|
42
43
|
- test/document_test.rb
|
43
44
|
- test/element_test.rb
|
@@ -69,6 +70,6 @@ rubyforge_project:
|
|
69
70
|
rubygems_version: 1.6.2
|
70
71
|
signing_key:
|
71
72
|
specification_version: 3
|
72
|
-
summary:
|
73
|
+
summary: Object Oriented SAX Parsing
|
73
74
|
test_files: []
|
74
75
|
|