rhash 0.0.4 → 0.0.5
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/rhash.rb +59 -0
- data/test/test.rb +11 -10
- metadata +5 -5
data/lib/rhash.rb
CHANGED
@@ -454,6 +454,52 @@ class RHash
|
|
454
454
|
end
|
455
455
|
end
|
456
456
|
|
457
|
+
#
|
458
|
+
# Converts the RHash to a XML.
|
459
|
+
#
|
460
|
+
# x= RHash.new
|
461
|
+
#
|
462
|
+
# x["code"] = RHash.new
|
463
|
+
#
|
464
|
+
# x["code"]["color"] = "0x0454"
|
465
|
+
#
|
466
|
+
# x["code"]["size"] = 24
|
467
|
+
#
|
468
|
+
# x["code"]["letter"] = "Arial"
|
469
|
+
#
|
470
|
+
# x["code"]["mode"] = RHash.new
|
471
|
+
#
|
472
|
+
# x["code"]["mode"]["present"] = "Love"
|
473
|
+
#
|
474
|
+
# x["code"]["mode"]["to"] = "Rose Mary"
|
475
|
+
#
|
476
|
+
# x.to_xml #=> <code>
|
477
|
+
#
|
478
|
+
# <color>0x0454</color>
|
479
|
+
#
|
480
|
+
# <size>24</size>
|
481
|
+
#
|
482
|
+
# <letter>Arial</letter>
|
483
|
+
#
|
484
|
+
# <mode>
|
485
|
+
#
|
486
|
+
# <present>Love</present>
|
487
|
+
#
|
488
|
+
# <to>Rose Mary</to>
|
489
|
+
#
|
490
|
+
# </mode>
|
491
|
+
#
|
492
|
+
# </code>
|
493
|
+
#
|
494
|
+
def to_xml
|
495
|
+
msg_xml = ''
|
496
|
+
@hash.each do |info|
|
497
|
+
msg_xml += "<#{info.key}>#{xml(info.value)}</#{info.key}>\n"
|
498
|
+
end
|
499
|
+
msg_xml
|
500
|
+
end
|
501
|
+
alias :to_html :to_xml
|
502
|
+
|
457
503
|
#
|
458
504
|
# See Hash::to_a
|
459
505
|
#
|
@@ -498,6 +544,19 @@ class RHash
|
|
498
544
|
|
499
545
|
private
|
500
546
|
|
547
|
+
def xml(info)
|
548
|
+
msg_xml = ""
|
549
|
+
if info.is_a? RHash
|
550
|
+
msg_xml += "\n"
|
551
|
+
info.each do |subinfo|
|
552
|
+
msg_xml += "<#{subinfo[0]}>#{xml(subinfo[1])}</#{subinfo[0]}>\n"
|
553
|
+
end
|
554
|
+
else
|
555
|
+
msg_xml += "#{info}"
|
556
|
+
end
|
557
|
+
msg_xml
|
558
|
+
end
|
559
|
+
|
501
560
|
def equal(other)
|
502
561
|
if other.size == self.size
|
503
562
|
hits = other.size
|
data/test/test.rb
CHANGED
@@ -13,15 +13,16 @@ n[:m] = 5
|
|
13
13
|
#x["r"] = 6
|
14
14
|
|
15
15
|
x= RHash.new
|
16
|
-
x["
|
17
|
-
x["
|
18
|
-
x["
|
19
|
-
x["
|
20
|
-
|
16
|
+
x["body"] = RHash.new
|
17
|
+
x["body"]["color"] = "0x0454"
|
18
|
+
x["body"]["size"] = 24
|
19
|
+
x["body"]["letter"] = "Arial"
|
20
|
+
x["body"]["mode"] = RHash.new
|
21
|
+
x["body"]["mode"]["present"] = "Love"
|
22
|
+
x["body"]["mode"]["to"] = "Rose Mary"
|
21
23
|
#puts n == x
|
22
24
|
#puts n == 5
|
23
|
-
|
24
|
-
a
|
25
|
-
|
26
|
-
puts
|
27
|
-
puts b.inspect
|
25
|
+
#a,b = n.diff x
|
26
|
+
#puts a.inspect
|
27
|
+
#puts b.inspect
|
28
|
+
puts x.to_html
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rodrigo Mello Nardi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-16 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -63,6 +63,6 @@ rubyforge_project:
|
|
63
63
|
rubygems_version: 1.3.7
|
64
64
|
signing_key:
|
65
65
|
specification_version: 3
|
66
|
-
summary:
|
66
|
+
summary: An ordenable hash.
|
67
67
|
test_files:
|
68
68
|
- test/test.rb
|