yaxml 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/LICENSE +165 -0
- data/README +49 -0
- data/Rakefile +53 -0
- data/doc/rdoc/classes/YAXML.html +465 -0
- data/doc/rdoc/classes/YAXML/Yaxml.html +277 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/CHANGELOG.html +126 -0
- data/doc/rdoc/files/LICENSE.html +311 -0
- data/doc/rdoc/files/README.html +176 -0
- data/doc/rdoc/files/lib/yaxml_rb.html +170 -0
- data/doc/rdoc/fr_class_index.html +28 -0
- data/doc/rdoc/fr_file_index.html +30 -0
- data/doc/rdoc/fr_method_index.html +34 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/lib/simple_test.xml +12 -0
- data/lib/simple_test.yml +9 -0
- data/lib/yaxml.rb +354 -0
- data/test/files/simple_test.xml +12 -0
- data/test/files/simple_test.yml +9 -0
- data/test/files/test.xml +5 -0
- data/test/files/test.xml~ +5 -0
- data/test/files/test.yml +28 -0
- data/test/load_files.rb +9 -0
- data/test/test_parser.rb +98 -0
- metadata +91 -0
data/test/files/test.xml
ADDED
@@ -0,0 +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>
|
@@ -0,0 +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>
|
data/test/files/test.yml
ADDED
@@ -0,0 +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.
|
data/test/load_files.rb
ADDED
data/test/test_parser.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#require 'ruby-debug'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'yaxml'
|
5
|
+
require 'load_files'
|
6
|
+
|
7
|
+
class TestParser < Test::Unit::TestCase
|
8
|
+
|
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
|
+
def test_parser_from_yaml_to_yaxml_complex_case
|
18
|
+
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/test.yml'], {:root_name => "invoice"} )
|
19
|
+
|
20
|
+
assert_equal TestFiles::FILES['files/test.xml'], yaxml.to_s
|
21
|
+
end
|
22
|
+
|
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
|
+
def test_parser_from_yaxml_to_yaml_complex_case
|
36
|
+
yaxml = YAXML::Yaxml.new( TestFiles::FILES['files/test.xml'], {:from_yaxml => true} )
|
37
|
+
json_to_compare = yaxml.to_json
|
38
|
+
|
39
|
+
correct_json = YAML::load TestFiles::FILES['files/test.yml']
|
40
|
+
correct_json = stringing_values correct_json
|
41
|
+
correct_json = delete_last_eol correct_json
|
42
|
+
|
43
|
+
assert_block "#{json_to_compare.inspect} expected but was #{correct_json.inspect}" do
|
44
|
+
json_to_compare == correct_json
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
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
|
+
# Convert a JSON as:
|
59
|
+
# { "one" => 1, "two" => 2 }
|
60
|
+
# to:
|
61
|
+
# { "one" => "1", "two" => "2" }
|
62
|
+
# This make the json easier to compare
|
63
|
+
def stringing_values( hash )
|
64
|
+
if hash.is_a?Hash
|
65
|
+
hash.each_pair do | k, v |
|
66
|
+
hash[k] = stringing_values v
|
67
|
+
end
|
68
|
+
elsif hash.is_a?Array
|
69
|
+
hash.map do | v |
|
70
|
+
stringing_values v
|
71
|
+
end
|
72
|
+
else # case of String, Float, Date...
|
73
|
+
hash = hash.to_s
|
74
|
+
end
|
75
|
+
hash
|
76
|
+
end
|
77
|
+
|
78
|
+
# Find all string in a JSON to convert them from:
|
79
|
+
# "458 Walkman Dr.\nSuite #292\n"
|
80
|
+
# to:
|
81
|
+
# "458 Walkman Dr.\nSuite #292"
|
82
|
+
def delete_last_eol( hash )
|
83
|
+
if hash.is_a?Hash
|
84
|
+
hash.each_pair do | k, v |
|
85
|
+
hash[k] = delete_last_eol v
|
86
|
+
end
|
87
|
+
elsif hash.is_a?Array
|
88
|
+
hash.map do | v |
|
89
|
+
delete_last_eol v
|
90
|
+
end
|
91
|
+
elsif String
|
92
|
+
# If last character is \n, get out that character.
|
93
|
+
hash.sub!(/\n$/, '')
|
94
|
+
end
|
95
|
+
hash
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yaxml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Diego Moreno
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-27 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Library to manage YAXML files
|
17
|
+
email: dmoreno@dit.upm.es
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- CHANGELOG
|
25
|
+
- LICENSE
|
26
|
+
files:
|
27
|
+
- CHANGELOG
|
28
|
+
- LICENSE
|
29
|
+
- README
|
30
|
+
- Rakefile
|
31
|
+
- doc/rdoc
|
32
|
+
- doc/rdoc/fr_method_index.html
|
33
|
+
- doc/rdoc/fr_file_index.html
|
34
|
+
- doc/rdoc/created.rid
|
35
|
+
- doc/rdoc/rdoc-style.css
|
36
|
+
- doc/rdoc/classes
|
37
|
+
- doc/rdoc/classes/YAXML
|
38
|
+
- doc/rdoc/classes/YAXML/Yaxml.html
|
39
|
+
- doc/rdoc/classes/YAXML.html
|
40
|
+
- doc/rdoc/index.html
|
41
|
+
- doc/rdoc/fr_class_index.html
|
42
|
+
- doc/rdoc/files
|
43
|
+
- doc/rdoc/files/LICENSE.html
|
44
|
+
- doc/rdoc/files/lib
|
45
|
+
- doc/rdoc/files/lib/yaxml_rb.html
|
46
|
+
- doc/rdoc/files/CHANGELOG.html
|
47
|
+
- doc/rdoc/files/README.html
|
48
|
+
- test/test_parser.rb
|
49
|
+
- test/load_files.rb
|
50
|
+
- test/files
|
51
|
+
- test/files/test.yml
|
52
|
+
- test/files/simple_test.xml
|
53
|
+
- test/files/simple_test.yml
|
54
|
+
- test/files/test.xml~
|
55
|
+
- test/files/test.xml
|
56
|
+
- lib/simple_test.xml
|
57
|
+
- lib/simple_test.yml
|
58
|
+
- lib/yaxml.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: http://yaxml.rubyforge.com/
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options:
|
63
|
+
- --quiet
|
64
|
+
- --title
|
65
|
+
- The YAXML Module Reference
|
66
|
+
- --main
|
67
|
+
- README
|
68
|
+
- --inline-source
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
version:
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.3.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 2
|
89
|
+
summary: Library to manage YAXML files
|
90
|
+
test_files: []
|
91
|
+
|