oxm 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,6 @@
1
+ ### 0.1.2 / 2011/09/20
2
+ * Bug fix: Invalid handling of empty content
3
+
1
4
  ### 0.1.1 / 2011/09/19
2
5
  * Bug fix: OXM::Object#compact! incorrectly nilified elements
3
6
  ### 0.1.0 / 2011/09/19
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/oxm/object.rb CHANGED
@@ -12,14 +12,14 @@ module OXM
12
12
  # @return [String]
13
13
  def content= val
14
14
  @cdata = false
15
- process val
15
+ @data = val
16
16
  end
17
17
 
18
18
  # @param [String] val CDATA content
19
19
  # @return [String]
20
20
  def cdata= val
21
21
  @cdata = true
22
- process val
22
+ @data = val
23
23
  end
24
24
 
25
25
  # @return [Boolean]
@@ -43,9 +43,9 @@ module OXM
43
43
  end
44
44
  if node.content
45
45
  if node.cdata?
46
- builder.cdata! node.content
46
+ builder.cdata! node.to_s
47
47
  else
48
- builder.text! node.content
48
+ builder.text! node.to_s
49
49
  end
50
50
  end
51
51
  end
@@ -143,12 +143,6 @@ module OXM
143
143
  raise NoMethodError.new("undefined method or attribute `#{symb}'")
144
144
  end
145
145
  end
146
-
147
- def process str
148
- str = str.to_s.strip
149
- @data = str
150
- end
151
-
152
146
  end#Object
153
147
  end#OXM
154
148
 
@@ -34,8 +34,17 @@ module OXM
34
34
 
35
35
  def end_element tag
36
36
  unless @objects.empty?
37
+ obj = @objects.pop
38
+
39
+ # Strip content
40
+ if obj.cdata?
41
+ obj.cdata = obj.to_s.strip
42
+ else
43
+ obj.content = obj.to_s.strip
44
+ end
45
+ obj.content = nil if obj.to_s.empty?
46
+
37
47
  if match?
38
- obj = @objects.pop
39
48
  if @block
40
49
  @block.call obj
41
50
  else
@@ -43,7 +52,6 @@ module OXM
43
52
  end
44
53
  @object = nil
45
54
  else
46
- @objects.pop
47
55
  @object = @objects.last
48
56
  end
49
57
  end
data/test/test_oxm.rb CHANGED
@@ -109,6 +109,25 @@ class TestOxm < Test::Unit::TestCase
109
109
  end
110
110
  end
111
111
 
112
+ def test_nil
113
+ str = <<-EOF
114
+ <container>
115
+ <item></item>
116
+ <item> </item>
117
+ <item>
118
+ </item>
119
+ <item>
120
+
121
+ </item>
122
+ </container>
123
+ EOF
124
+
125
+ OXM.from_xml(str, 'container/item') do |item|
126
+ assert_nil item.content
127
+ assert_equal "<item></item>", item.to_xml
128
+ end
129
+ end
130
+
112
131
  def test_compaction
113
132
  str = <<-EOF
114
133
  <container attr1="1" attr2="2">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-19 00:00:00.000000000Z
12
+ date: 2011-09-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
16
- requirement: &2152887260 !ruby/object:Gem::Requirement
16
+ requirement: &2152490720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152887260
24
+ version_requirements: *2152490720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &2152885680 !ruby/object:Gem::Requirement
27
+ requirement: &2152489620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152885680
35
+ version_requirements: *2152489620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &2152884200 !ruby/object:Gem::Requirement
38
+ requirement: &2152488420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2152884200
46
+ version_requirements: *2152488420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &2152883120 !ruby/object:Gem::Requirement
49
+ requirement: &2152485060 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2152883120
57
+ version_requirements: *2152485060
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &2152882320 !ruby/object:Gem::Requirement
60
+ requirement: &2152483840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2152882320
68
+ version_requirements: *2152483840
69
69
  description: A tiny Object-XML-Mapper using Nokogiri SAX parser
70
70
  email: junegunn.c@gmail.com
71
71
  executables: []
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  segments:
104
104
  - 0
105
- hash: 723951543129720723
105
+ hash: 3232406390729243010
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements: