data-converter 0.1 → 0.1.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/README.rdoc +2 -1
- data/data-converter.gemspec +1 -1
- data/lib/data-converter.rb +13 -8
- data/test/test.rb +6 -6
- metadata +5 -6
data/README.rdoc
CHANGED
data/data-converter.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do | spec |
|
2
2
|
spec.name = "data-converter"
|
3
|
-
spec.version = "0.1"
|
3
|
+
spec.version = "0.1.5"
|
4
4
|
spec.summary = "Ruby Data convert to HTML. It is under the devlopment."
|
5
5
|
spec.description = "Hash and Array convert to HTML Element (Array => ul, Hash => dl)."
|
6
6
|
spec.homepage = "https://github.com/namusyaka/data-converter"
|
data/lib/data-converter.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
class String
|
2
|
+
def escapeHTML
|
3
|
+
self.gsub(/&/n, '&').gsub(/\"/n, '"').gsub(/>/n, '>').gsub(/</n, '<').gsub(/'/, ''')
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
1
7
|
class DataConverter
|
2
8
|
attr_reader :data
|
3
9
|
|
@@ -24,8 +30,7 @@ class DataConverter
|
|
24
30
|
when HASH
|
25
31
|
list = <<-DL
|
26
32
|
<dl>
|
27
|
-
#{ convert_to_dl_childs(data)
|
28
|
-
</dl>
|
33
|
+
#{ convert_to_dl_childs(data) }</dl>
|
29
34
|
DL
|
30
35
|
else
|
31
36
|
return data
|
@@ -44,21 +49,21 @@ class DataConverter
|
|
44
49
|
if check_data?(e)
|
45
50
|
"<li>#{ convert(e) }</li>"
|
46
51
|
else
|
47
|
-
"<li>#{ e }</li>"
|
52
|
+
"<li>#{ e.to_s.escapeHTML }</li>"
|
48
53
|
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
|
52
57
|
def convert_to_dl_childs(data)
|
53
|
-
childs =
|
58
|
+
childs = ""
|
54
59
|
data.each_pair do | key, value |
|
55
|
-
childs
|
60
|
+
childs += "<dt>#{ key.to_s.escapeHTML }</dt>\n"
|
56
61
|
if check_data?(value)
|
57
|
-
childs
|
62
|
+
childs += "<dd>#{ convert(value) }</dd>\n"
|
58
63
|
else
|
59
|
-
childs
|
64
|
+
childs += "<dd>#{ value.to_s.escapeHTML }</dd>\n"
|
60
65
|
end
|
61
66
|
end
|
62
67
|
childs
|
63
68
|
end
|
64
|
-
end
|
69
|
+
end
|
data/test/test.rb
CHANGED
@@ -45,13 +45,13 @@ class Test_DataConverter < Test::Unit::TestCase
|
|
45
45
|
@class = DataConverter
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
def test_array_parse
|
49
|
+
assert_equal(ARRAY_RESULT, @class.parse(@array_data))
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
def test_hash_parse
|
53
|
+
assert_equal(HASH_RESULT, @class.parse(@hash_data))
|
54
|
+
end
|
55
55
|
|
56
56
|
def test_other_approach
|
57
57
|
assert_equal(HASH_RESULT, DataConverter.new(@hash_data).convert)
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data-converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- namusyaka
|
@@ -14,8 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-11-
|
18
|
-
default_executable:
|
18
|
+
date: 2011-11-14 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
21
|
description: Hash and Array convert to HTML Element (Array => ul, Hash => dl).
|
@@ -31,7 +31,6 @@ files:
|
|
31
31
|
- README.rdoc
|
32
32
|
- lib/data-converter.rb
|
33
33
|
- test/test.rb
|
34
|
-
has_rdoc: true
|
35
34
|
homepage: https://github.com/namusyaka/data-converter
|
36
35
|
licenses: []
|
37
36
|
|
@@ -61,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
60
|
requirements: []
|
62
61
|
|
63
62
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.
|
63
|
+
rubygems_version: 1.8.1
|
65
64
|
signing_key:
|
66
65
|
specification_version: 3
|
67
66
|
summary: Ruby Data convert to HTML. It is under the devlopment.
|