data-converter 0.1 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,5 +1,6 @@
1
1
  =data-converter
2
2
 
3
+
3
4
  ==Install
4
5
  gem install data-converter
5
6
 
@@ -13,7 +14,7 @@
13
14
 
14
15
  puts DataConverter.parse({
15
16
  :a => "b",
16
- :c => { :d => [0, 1, 2] }
17
+ :c => { :d => ["<>&\"'", 1, 2] }
17
18
  })
18
19
 
19
20
  ==License
@@ -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"
@@ -1,3 +1,9 @@
1
+ class String
2
+ def escapeHTML
3
+ self.gsub(/&/n, '&amp;').gsub(/\"/n, '&quot;').gsub(/>/n, '&gt;').gsub(/</n, '&lt;').gsub(/'/, '&#039;')
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).join("\n") }
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 << "<dt>#{ key }</dt>"
60
+ childs += "<dt>#{ key.to_s.escapeHTML }</dt>\n"
56
61
  if check_data?(value)
57
- childs << "<dd>#{ convert(value) }</dd>"
62
+ childs += "<dd>#{ convert(value) }</dd>\n"
58
63
  else
59
- childs << "<dd>#{ value }</dd>"
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
- def test_array_parse
49
- assert_equal(ARRAY_RESULT, @class.parse(@array_data))
50
- end
48
+ def test_array_parse
49
+ assert_equal(ARRAY_RESULT, @class.parse(@array_data))
50
+ end
51
51
 
52
- def test_hash_parse
53
- assert_equal(HASH_RESULT, @class.parse(@hash_data))
54
- end
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: 9
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- version: "0.1"
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-12 00:00:00 +09:00
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.5.0
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.