data_formatter 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/data_formatter.rb +1 -1
- data/lib/data_formatter/value.rb +4 -1
- data/lib/data_formatter/version.rb +1 -1
- data/test/base_test.rb +20 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1af7f628b75ee44be06f03b2dfe322b2e4707bd
|
4
|
+
data.tar.gz: a7d764f13700bd53540b77ee2732e403980f7c75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c859edd65c700c50566bdb1238d52c337230df313eff5e2a4521b6e0ecab09dbc546d723a66f309c1a9054bf7012a291da88789fd06afe2c1eba6860954f09
|
7
|
+
data.tar.gz: 210101527f4dbc310ea16337ec32185670e1a91ad1e748efe266d066a7ad8d4eca8ae6fc8e227012eade7672127eacf27316d3fcdbb0745d50245ee260915419
|
data/lib/data_formatter.rb
CHANGED
data/lib/data_formatter/value.rb
CHANGED
@@ -37,7 +37,10 @@ module DataFormatter
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def format_string
|
40
|
-
|
40
|
+
escaped_value = { "\a" => '\a', "\b" => '\b', "\r" => '\r', "\n" => '\n', "\s" => '\s', "\t" => '\t' }.inject(value) do |memo, pair|
|
41
|
+
memo.gsub(pair[0], pair[1])
|
42
|
+
end
|
43
|
+
mark_up(data: escaped_value, surround: '"', kind: "string" )
|
41
44
|
end
|
42
45
|
|
43
46
|
def format_boolean
|
data/test/base_test.rb
CHANGED
@@ -18,6 +18,18 @@ describe "version" do
|
|
18
18
|
DataFormatter.format({"a" => '"hi"'}).must_equal("<span class=\"curly-bracket\">{</span><span class=\"key string\">"a"</span><span class=\"hashrocket\"> => </span><span class=\"string\">"\\"hi\\""</span><span class=\"curly-bracket\">}</span>")
|
19
19
|
end
|
20
20
|
|
21
|
+
it "escapes newlines in strings" do
|
22
|
+
DataFormatter.format({"a" => "b\nc"}).must_equal("<span class=\"curly-bracket\">{</span><span class=\"key string\">"a"</span><span class=\"hashrocket\"> => </span><span class=\"string\">"b\\nc"</span><span class=\"curly-bracket\">}</span>")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "escapes carragereturns in strings" do
|
26
|
+
DataFormatter.format({"a" => "b\rc"}).must_equal("<span class=\"curly-bracket\">{</span><span class=\"key string\">"a"</span><span class=\"hashrocket\"> => </span><span class=\"string\">"b\\rc"</span><span class=\"curly-bracket\">}</span>")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "escapes tabs in strings" do
|
30
|
+
DataFormatter.format({"a" => "b\tc"}).must_equal("<span class=\"curly-bracket\">{</span><span class=\"key string\">"a"</span><span class=\"hashrocket\"> => </span><span class=\"string\">"b\\tc"</span><span class=\"curly-bracket\">}</span>")
|
31
|
+
end
|
32
|
+
|
21
33
|
it "formats a string => number hash" do
|
22
34
|
DataFormatter.format({"a" => 2}).must_equal("<span class=\"curly-bracket\">{</span><span class=\"key string\">"a"</span><span class=\"hashrocket\"> => </span><span class=\"number\">2</span><span class=\"curly-bracket\">}</span>")
|
23
35
|
end
|
@@ -59,4 +71,12 @@ describe "version" do
|
|
59
71
|
DataFormatter.format(data)
|
60
72
|
end
|
61
73
|
|
74
|
+
it "Formats a string" do
|
75
|
+
DataFormatter.format("Hello").must_equal("<span class=\"string\">"Hello"</span>")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "Formats an array" do
|
79
|
+
DataFormatter.format(["Hello", "there"]).must_equal("<span class=\"bracket\">[</span>\n <span class=\"string\">"Hello"</span>,\n <span class=\"string\">"there"</span>\n<span class=\"bracket\">]</span>")
|
80
|
+
end
|
81
|
+
|
62
82
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Starr Horne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|