yaxml 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +6 -3
- data/Rakefile +8 -2
- data/doc/rdoc/classes/YAXML.html +4 -4
- data/doc/rdoc/classes/YAXML/Yaxml.html +4 -4
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGELOG.html +1 -1
- data/doc/rdoc/files/LICENSE.html +1 -1
- data/doc/rdoc/files/README.html +7 -6
- data/doc/rdoc/files/lib/yaxml_rb.html +1 -1
- data/lib/yaxml.rb +18 -18
- data/test/files/simple_test.xml +1 -12
- data/test/files/simple_test.yml +0 -1
- data/test/files/test.xml +5 -5
- data/test/files/test.yml +28 -28
- data/test/load_files.rb +4 -1
- data/test/{test_parser.rb → test_complex_parser.rb} +2 -30
- data/test/test_simple_parser.rb +49 -0
- metadata +5 -7
- data/lib/simple_test.xml +0 -12
- data/lib/simple_test.yml +0 -9
- data/test/files/test.xml~ +0 -5
data/README
CHANGED
@@ -28,7 +28,7 @@ You can use this module in two ways:
|
|
28
28
|
|
29
29
|
YAXML is <b>standalone library</b>. It requires no other libraries. Just Ruby!
|
30
30
|
|
31
|
-
Author:: Diego Moreno (dmoreno
|
31
|
+
Author:: Diego Moreno (dmoreno AT dit.upm.es)
|
32
32
|
License:: GNU Lesser General Public License (aka LGPL)
|
33
33
|
|
34
34
|
== Installing YAXML
|
@@ -44,6 +44,9 @@ You have probably got the gem, right? To load YAXML:
|
|
44
44
|
require 'rubygems'
|
45
45
|
require 'yaxml'
|
46
46
|
|
47
|
-
|
47
|
+
== Documentation
|
48
|
+
|
49
|
+
You can see the documentation in the project home page:
|
50
|
+
|
51
|
+
{YAXML Gem Homepage}[http://yaxml.rubyforge.org]
|
48
52
|
|
49
|
-
require 'yaxml'
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ include FileUtils
|
|
8
8
|
|
9
9
|
NAME = "yaxml"
|
10
10
|
REV = `svn info`[/Revision: (\d+)/, 1] rescue nil
|
11
|
-
VERS = ENV['VERSION'] || "0.0.
|
11
|
+
VERS = ENV['VERSION'] || "0.0.8" + (REV ? ".#{REV}" : "")
|
12
12
|
PKG = "#{NAME}-#{VERS}"
|
13
13
|
RDOC_OPTS = ['--quiet', '--title', 'The YAXML Module Reference', '--main', 'README', '--inline-source']
|
14
14
|
PKG_FILES = %w(CHANGELOG LICENSE README Rakefile) + Dir.glob("{doc,test,lib}/**/*")
|
@@ -28,7 +28,7 @@ SPEC =
|
|
28
28
|
s.homepage = 'http://yaxml.rubyforge.com/'
|
29
29
|
s.files = PKG_FILES
|
30
30
|
s.require_paths = ["lib"]
|
31
|
-
|
31
|
+
s.rubyforge_project = "yaxml"
|
32
32
|
end
|
33
33
|
|
34
34
|
desc "Does a test run"
|
@@ -51,3 +51,9 @@ Rake::RDocTask.new do |rdoc|
|
|
51
51
|
rdoc.main = "README"
|
52
52
|
rdoc.rdoc_files.add ['README', 'CHANGELOG', 'LICENSE', 'lib/*.rb']
|
53
53
|
end
|
54
|
+
|
55
|
+
Rake::GemPackageTask.new(SPEC) do |p|
|
56
|
+
p.need_tar = true
|
57
|
+
p.gem_spec = SPEC
|
58
|
+
end
|
59
|
+
|
data/doc/rdoc/classes/YAXML.html
CHANGED
@@ -191,7 +191,7 @@ Example of use:
|
|
191
191
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
192
192
|
<div class="method-source-code" id="M000002-source">
|
193
193
|
<pre>
|
194
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
194
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 188</span>
|
195
195
|
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">json2yaxml</span>( <span class="ruby-identifier">json_to_encode</span>, <span class="ruby-identifier">options</span>={} )
|
196
196
|
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">json_to_encode</span>
|
197
197
|
|
@@ -294,7 +294,7 @@ Example of use:
|
|
294
294
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
295
295
|
<div class="method-source-code" id="M000001-source">
|
296
296
|
<pre>
|
297
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
297
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 143</span>
|
298
298
|
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">yaml2yaxml</span>( <span class="ruby-identifier">source</span>, <span class="ruby-identifier">options</span>={} )
|
299
299
|
|
300
300
|
<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:root_name</span>] <span class="ruby-operator">||=</span> <span class="ruby-constant">DEFAULT_ROOT_NAME</span>
|
@@ -364,7 +364,7 @@ Example of use:
|
|
364
364
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
365
365
|
<div class="method-source-code" id="M000004-source">
|
366
366
|
<pre>
|
367
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
367
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 287</span>
|
368
368
|
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">yaxml2json</span>( <span class="ruby-identifier">source</span> )
|
369
369
|
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">source</span>
|
370
370
|
|
@@ -441,7 +441,7 @@ Example of use:
|
|
441
441
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
442
442
|
<div class="method-source-code" id="M000003-source">
|
443
443
|
<pre>
|
444
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
444
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 260</span>
|
445
445
|
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">yaxml2yaml</span>( <span class="ruby-identifier">source</span> )
|
446
446
|
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">yaxml2json</span>( <span class="ruby-identifier">source</span> ).<span class="ruby-identifier">to_yaml</span>
|
447
447
|
<span class="ruby-keyword kw">end</span>
|
@@ -157,7 +157,7 @@ Example of use:
|
|
157
157
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
158
158
|
<div class="method-source-code" id="M000005-source">
|
159
159
|
<pre>
|
160
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
160
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 63</span>
|
161
161
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>( <span class="ruby-identifier">source</span>, <span class="ruby-identifier">options</span>={} )
|
162
162
|
<span class="ruby-keyword kw">super</span>()
|
163
163
|
|
@@ -199,7 +199,7 @@ object.
|
|
199
199
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
200
200
|
<div class="method-source-code" id="M000007-source">
|
201
201
|
<pre>
|
202
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
202
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 86</span>
|
203
203
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_json</span>
|
204
204
|
<span class="ruby-constant">YAXML</span><span class="ruby-operator">::</span><span class="ruby-identifier">yaxml2json</span> <span class="ruby-keyword kw">self</span>
|
205
205
|
<span class="ruby-keyword kw">end</span>
|
@@ -226,7 +226,7 @@ object.
|
|
226
226
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
227
227
|
<div class="method-source-code" id="M000006-source">
|
228
228
|
<pre>
|
229
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
229
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 81</span>
|
230
230
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_yaml</span>
|
231
231
|
<span class="ruby-constant">YAXML</span><span class="ruby-operator">::</span><span class="ruby-identifier">yaxml2yaml</span> <span class="ruby-keyword kw">self</span>
|
232
232
|
<span class="ruby-keyword kw">end</span>
|
@@ -253,7 +253,7 @@ href="../YAXML.html">YAXML</a> object.
|
|
253
253
|
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
254
254
|
<div class="method-source-code" id="M000008-source">
|
255
255
|
<pre>
|
256
|
-
<span class="ruby-comment cmt"># File lib/yaxml.rb, line
|
256
|
+
<span class="ruby-comment cmt"># File lib/yaxml.rb, line 91</span>
|
257
257
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_yaxml</span>
|
258
258
|
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_s</span>
|
259
259
|
<span class="ruby-keyword kw">end</span>
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Wed, 01 Apr 2009 11:34:02 +0200
|
data/doc/rdoc/files/LICENSE.html
CHANGED
data/doc/rdoc/files/README.html
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Wed Apr 01 11:33:43 +0200 2009</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -112,7 +112,7 @@ You can use this module in two ways:
|
|
112
112
|
requires no other libraries. Just Ruby!
|
113
113
|
</p>
|
114
114
|
<table>
|
115
|
-
<tr><td valign="top">Author:</td><td>Diego Moreno (dmoreno
|
115
|
+
<tr><td valign="top">Author:</td><td>Diego Moreno (dmoreno AT dit.upm.es)
|
116
116
|
|
117
117
|
</td></tr>
|
118
118
|
<tr><td valign="top">License:</td><td>GNU Lesser General Public License (aka LGPL)
|
@@ -135,12 +135,13 @@ href="../classes/YAXML.html">YAXML</a>:
|
|
135
135
|
require 'rubygems'
|
136
136
|
require 'yaxml'
|
137
137
|
</pre>
|
138
|
+
<h2>Documentation</h2>
|
138
139
|
<p>
|
139
|
-
|
140
|
+
You can see the documentation in the project home page:
|
141
|
+
</p>
|
142
|
+
<p>
|
143
|
+
<a href="http://yaxml.rubyforge.org">YAXML Gem Homepage</a>
|
140
144
|
</p>
|
141
|
-
<pre>
|
142
|
-
require 'yaxml'
|
143
|
-
</pre>
|
144
145
|
|
145
146
|
</div>
|
146
147
|
|
data/lib/yaxml.rb
CHANGED
@@ -34,8 +34,6 @@
|
|
34
34
|
# License:: GNU Lesser General Public License (aka LGPL)
|
35
35
|
#
|
36
36
|
|
37
|
-
#require 'ruby-debug'
|
38
|
-
|
39
37
|
require "rexml/document"
|
40
38
|
require 'yaml'
|
41
39
|
|
@@ -336,19 +334,21 @@ module YAXML
|
|
336
334
|
|
337
335
|
end
|
338
336
|
|
339
|
-
#
|
340
|
-
#
|
341
|
-
#doc
|
342
|
-
|
343
|
-
#doc
|
344
|
-
#
|
345
|
-
|
346
|
-
#
|
347
|
-
#
|
348
|
-
|
349
|
-
#
|
350
|
-
#
|
351
|
-
|
352
|
-
#
|
353
|
-
#
|
354
|
-
#
|
337
|
+
# Use examples
|
338
|
+
#
|
339
|
+
# doc = YAXML::yaml2yaxml "test.yml"
|
340
|
+
# puts doc.to_s
|
341
|
+
# doc.write( $stdout, 2 )
|
342
|
+
#
|
343
|
+
# doc = YAXML.yaxml2yaml_from_file "test.xml"
|
344
|
+
# puts doc.inspect
|
345
|
+
#
|
346
|
+
# yaxml = YAXML::Yaxml.new 'test2.yml'
|
347
|
+
# puts yaxml.to_s
|
348
|
+
#
|
349
|
+
# doc = REXML::Document.new yaxml.to_s
|
350
|
+
# doc.write( $stdout, 2 )
|
351
|
+
#
|
352
|
+
# yaxml.write( $stdout, 2 )
|
353
|
+
# puts yaxml.to_json.inspect
|
354
|
+
# puts yaxml.to_yaml
|
data/test/files/simple_test.xml
CHANGED
@@ -1,12 +1 @@
|
|
1
|
-
<root xmlns:yaml='http://yaml.org/xml'>
|
2
|
-
<three>
|
3
|
-
<_>apple</_>
|
4
|
-
<_>pear</_>
|
5
|
-
</three>
|
6
|
-
<two> 2.0 </two>
|
7
|
-
<one>1</one>
|
8
|
-
<four>
|
9
|
-
<bb>22</bb>
|
10
|
-
<aa>11</aa>
|
11
|
-
</four>
|
12
|
-
</root>
|
1
|
+
<root xmlns:yaml='http://yaml.org/xml'><three><_>apple</_><_>pear</_></three><two>2.0</two><one>1</one><four><bb>22</bb><aa>11</aa></four></root>
|
data/test/files/simple_test.yml
CHANGED
data/test/files/test.xml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
<invoice xmlns:yaml='http://yaml.org/xml'><tax>251.42</tax><number>34843</number><comments>Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.</comments><ship-to><address><city>Royal Oak</city><postal>48046</postal><lines>458 Walkman Dr.
|
2
|
-
Suite #292
|
3
|
-
</lines><state>MI</state></address><family>Dumars</family><given>Chris</given></ship-to><bill-to><address><city>Royal Oak</city><postal>48046</postal><lines>458 Walkman Dr.
|
4
|
-
Suite #292
|
5
|
-
</lines><state>MI</state></address><family>Dumars</family><given>Chris</given></bill-to><total>4443.52</total><date>2001-01-23</date><product><_><price>450.0</price><quantity>4</quantity><sku>BL394D</sku><description>Basketball</description></_><_><price>2392.0</price><quantity>1</quantity><sku>BL4438H</sku><description>Super Hoop</description></_></product></invoice>
|
1
|
+
<invoice xmlns:yaml='http://yaml.org/xml'><tax>251.42</tax><number>34843</number><comments>Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.</comments><ship-to><address><city>Royal Oak</city><postal>48046</postal><lines>458 Walkman Dr.
|
2
|
+
Suite #292
|
3
|
+
</lines><state>MI</state></address><family>Dumars</family><given>Chris</given></ship-to><bill-to><address><city>Royal Oak</city><postal>48046</postal><lines>458 Walkman Dr.
|
4
|
+
Suite #292
|
5
|
+
</lines><state>MI</state></address><family>Dumars</family><given>Chris</given></bill-to><total>4443.52</total><date>2001-01-23</date><product><_><price>450.0</price><quantity>4</quantity><sku>BL394D</sku><description>Basketball</description></_><_><price>2392.0</price><quantity>1</quantity><sku>BL4438H</sku><description>Super Hoop</description></_></product></invoice>
|
data/test/files/test.yml
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
number: 34843
|
2
|
-
date : 2001-01-23
|
3
|
-
bill-to: &id001
|
4
|
-
given : Chris
|
5
|
-
family : Dumars
|
6
|
-
address:
|
7
|
-
lines: |
|
8
|
-
458 Walkman Dr.
|
9
|
-
Suite #292
|
10
|
-
city : Royal Oak
|
11
|
-
state : MI
|
12
|
-
postal : 48046
|
13
|
-
ship-to: *id001
|
14
|
-
product:
|
15
|
-
- sku : BL394D
|
16
|
-
quantity : 4
|
17
|
-
description : Basketball
|
18
|
-
price : 450.00
|
19
|
-
- sku : BL4438H
|
20
|
-
quantity : 1
|
21
|
-
description : Super Hoop
|
22
|
-
price : 2392.00
|
23
|
-
tax : 251.42
|
24
|
-
total: 4443.52
|
25
|
-
comments: >
|
26
|
-
Late afternoon is best.
|
27
|
-
Backup contact is Nancy
|
28
|
-
Billsmer @ 338-4338.
|
1
|
+
number: 34843
|
2
|
+
date : 2001-01-23
|
3
|
+
bill-to: &id001
|
4
|
+
given : Chris
|
5
|
+
family : Dumars
|
6
|
+
address:
|
7
|
+
lines: |
|
8
|
+
458 Walkman Dr.
|
9
|
+
Suite #292
|
10
|
+
city : Royal Oak
|
11
|
+
state : MI
|
12
|
+
postal : 48046
|
13
|
+
ship-to: *id001
|
14
|
+
product:
|
15
|
+
- sku : BL394D
|
16
|
+
quantity : 4
|
17
|
+
description : Basketball
|
18
|
+
price : 450.00
|
19
|
+
- sku : BL4438H
|
20
|
+
quantity : 1
|
21
|
+
description : Super Hoop
|
22
|
+
price : 2392.00
|
23
|
+
tax : 251.42
|
24
|
+
total: 4443.52
|
25
|
+
comments: >
|
26
|
+
Late afternoon is best.
|
27
|
+
Backup contact is Nancy
|
28
|
+
Billsmer @ 338-4338.
|
data/test/load_files.rb
CHANGED
@@ -2,7 +2,10 @@ module TestFiles
|
|
2
2
|
file_content = {}
|
3
3
|
Dir.chdir(File.dirname(__FILE__)) do
|
4
4
|
Dir['files/*.{xml,yaml,yml,json,yaxml}'].each do |fname|
|
5
|
-
|
5
|
+
string_content_file = File.open( fname, "r" ).read
|
6
|
+
string_content_file.gsub!( /\r\n$/, '' )
|
7
|
+
string_content_file.gsub!( /\n$/, '' )
|
8
|
+
file_content[fname] = string_content_file
|
6
9
|
end
|
7
10
|
end
|
8
11
|
FILES = file_content
|
@@ -1,37 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#require '
|
2
|
+
#require 'rubygems'
|
3
|
+
#require 'ruby_debug'
|
3
4
|
require 'test/unit'
|
4
5
|
require 'yaxml'
|
5
6
|
require 'load_files'
|
6
7
|
|
7
8
|
class TestParser < Test::Unit::TestCase
|
8
9
|
|
9
|
-
def test_parser_from_yaml_to_yaxml_simple_case
|
10
|
-
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/simple_test.yml'], {:root_name => "root"} )
|
11
|
-
|
12
|
-
text_to_compare = convert_to_inline TestFiles::FILES['files/simple_test.xml']
|
13
|
-
|
14
|
-
assert_equal text_to_compare, yaxml.to_s
|
15
|
-
end
|
16
|
-
|
17
10
|
def test_parser_from_yaml_to_yaxml_complex_case
|
18
11
|
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/test.yml'], {:root_name => "invoice"} )
|
19
12
|
|
20
13
|
assert_equal TestFiles::FILES['files/test.xml'], yaxml.to_s
|
21
14
|
end
|
22
15
|
|
23
|
-
def test_parser_from_yaxml_to_yaml_simple_case
|
24
|
-
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/simple_test.xml'], {:from_yaxml => true} )
|
25
|
-
json_to_compare = yaxml.to_json
|
26
|
-
|
27
|
-
correct_json = YAML::load(TestFiles::FILES['files/simple_test.yml'])
|
28
|
-
correct_json = stringing_values( correct_json )
|
29
|
-
|
30
|
-
assert_block "Error parsing from YAXML" do
|
31
|
-
json_to_compare == correct_json
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
16
|
def test_parser_from_yaxml_to_yaml_complex_case
|
36
17
|
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/test.xml'], {:from_yaxml => true} )
|
37
18
|
json_to_compare = yaxml.to_json
|
@@ -46,15 +27,6 @@ class TestParser < Test::Unit::TestCase
|
|
46
27
|
end
|
47
28
|
|
48
29
|
private
|
49
|
-
# This method delete EOLs, tabs and spaces after '>' and before '<'
|
50
|
-
def convert_to_inline( string_to_convert )
|
51
|
-
string_to_convert.gsub!(/\n/, '') # delete EOLs
|
52
|
-
string_to_convert.gsub!(/\r/, '') # delete EOLs
|
53
|
-
string_to_convert.gsub!(/\t/, '') # delete tabs
|
54
|
-
string_to_convert.gsub!(/> +/, '>') # delete spaces after '>'
|
55
|
-
string_to_convert.gsub!(/ +</, '<') # delete spaces before '<'
|
56
|
-
end
|
57
|
-
|
58
30
|
# Convert a JSON as:
|
59
31
|
# { "one" => 1, "two" => 2 }
|
60
32
|
# to:
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#require 'rubygems'
|
3
|
+
#require 'ruby_debug'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'yaxml'
|
6
|
+
require 'load_files'
|
7
|
+
|
8
|
+
class TestSimpleParser < Test::Unit::TestCase
|
9
|
+
|
10
|
+
def test_parser_from_yaml_to_yaxml_simple_case
|
11
|
+
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/simple_test.yml'], {:root_name => "root"} )
|
12
|
+
|
13
|
+
assert_equal TestFiles::FILES['files/simple_test.xml'], yaxml.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_parser_from_yaxml_to_yaml_simple_case
|
17
|
+
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/simple_test.xml'], {:from_yaxml => true} )
|
18
|
+
json_to_compare = yaxml.to_json
|
19
|
+
|
20
|
+
correct_json = YAML::load(TestFiles::FILES['files/simple_test.yml'])
|
21
|
+
correct_json = stringing_values( correct_json )
|
22
|
+
|
23
|
+
assert_block "Error parsing from YAXML" do
|
24
|
+
json_to_compare == correct_json
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
# Convert a JSON as:
|
30
|
+
# { "one" => 1, "two" => 2 }
|
31
|
+
# to:
|
32
|
+
# { "one" => "1", "two" => "2" }
|
33
|
+
# This make the json easier to compare
|
34
|
+
def stringing_values( hash )
|
35
|
+
if hash.is_a?Hash
|
36
|
+
hash.each_pair do | k, v |
|
37
|
+
hash[k] = stringing_values v
|
38
|
+
end
|
39
|
+
elsif hash.is_a?Array
|
40
|
+
hash.map do | v |
|
41
|
+
stringing_values v
|
42
|
+
end
|
43
|
+
else # case of String, Float, Date...
|
44
|
+
hash = hash.to_s
|
45
|
+
end
|
46
|
+
hash
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaxml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego Moreno
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-01 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -45,16 +45,14 @@ files:
|
|
45
45
|
- doc/rdoc/files/lib/yaxml_rb.html
|
46
46
|
- doc/rdoc/files/CHANGELOG.html
|
47
47
|
- doc/rdoc/files/README.html
|
48
|
-
- test/
|
48
|
+
- test/test_simple_parser.rb
|
49
49
|
- test/load_files.rb
|
50
|
+
- test/test_complex_parser.rb
|
50
51
|
- test/files
|
51
52
|
- test/files/test.yml
|
52
53
|
- test/files/simple_test.xml
|
53
54
|
- test/files/simple_test.yml
|
54
|
-
- test/files/test.xml~
|
55
55
|
- test/files/test.xml
|
56
|
-
- lib/simple_test.xml
|
57
|
-
- lib/simple_test.yml
|
58
56
|
- lib/yaxml.rb
|
59
57
|
has_rdoc: true
|
60
58
|
homepage: http://yaxml.rubyforge.com/
|
@@ -82,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
80
|
version:
|
83
81
|
requirements: []
|
84
82
|
|
85
|
-
rubyforge_project:
|
83
|
+
rubyforge_project: yaxml
|
86
84
|
rubygems_version: 1.3.1
|
87
85
|
signing_key:
|
88
86
|
specification_version: 2
|
data/lib/simple_test.xml
DELETED
data/lib/simple_test.yml
DELETED
data/test/files/test.xml~
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
<invoice xmlns:yaml='http://yaml.org/xml'><tax>251.42</tax><number>34843</number><comments>Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.</comments><ship-to><address><city>Royal Oak</city><postal>48046</postal><lines>458 Walkman Dr.
|
2
|
-
Suite #292
|
3
|
-
</lines><state>MI</state></address><family>Dumars</family><given>Chris</given></ship-to><bill-to><address><city>Royal Oak</city><postal>48046</postal><lines>458 Walkman Dr.
|
4
|
-
Suite #292
|
5
|
-
</lines><state>MI</state></address><family>Dumars</family><given>Chris</given></bill-to><total>4443.52</total><date>2001-01-23</date><product><_><price>450.0</price><quantity>4</quantity><sku>BL394D</sku><description>Basketball</description></_><_><price>2392.0</price><quantity>1</quantity><sku>BL4438H</sku><description>Super Hoop</description></_></product></invoice>
|