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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3654332ffbe1b6c49126c5c743674b5a54a36ab0
4
- data.tar.gz: 0ee60110ead328207e043649a5203bf13ca49e5e
3
+ metadata.gz: f1af7f628b75ee44be06f03b2dfe322b2e4707bd
4
+ data.tar.gz: a7d764f13700bd53540b77ee2732e403980f7c75
5
5
  SHA512:
6
- metadata.gz: 07999b87ff216fad567ebca2216fde67b86f4d344b904cddaf806012bc4e49b7e464364b354222bb3a4f2e47668fdff2e5264da96718bf0a800c334784816c06
7
- data.tar.gz: 120b806122c993889b54386d7bf406f846e00e55a0ba7609b1c4c6af868311e8dd8a6b51f42d3ba2876edc1b21f9cfa5d0d4317017e27c9210a5b7ab63557001
6
+ metadata.gz: 81c859edd65c700c50566bdb1238d52c337230df313eff5e2a4521b6e0ecab09dbc546d723a66f309c1a9054bf7012a291da88789fd06afe2c1eba6860954f09
7
+ data.tar.gz: 210101527f4dbc310ea16337ec32185670e1a91ad1e748efe266d066a7ad8d4eca8ae6fc8e227012eade7672127eacf27316d3fcdbb0745d50245ee260915419
@@ -9,7 +9,7 @@ require "data_formatter/tag"
9
9
 
10
10
  module DataFormatter
11
11
  def self.format(data)
12
- HashCollection.new(data: data, indentation: Indentation.new()).to_s
12
+ Value.new(data: data, indentation: Indentation.new()).to_s
13
13
  end
14
14
 
15
15
  def self.format_lines(data)
@@ -37,7 +37,10 @@ module DataFormatter
37
37
  end
38
38
 
39
39
  def format_string
40
- mark_up(data: value, surround: '"', kind: "string" )
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
@@ -1,3 +1,3 @@
1
1
  module DataFormatter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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\">&quot;a&quot;</span><span class=\"hashrocket\">&nbsp;=&gt;&nbsp;</span><span class=\"string\">&quot;\\&quot;hi\\&quot;&quot;</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\">&quot;a&quot;</span><span class=\"hashrocket\">&nbsp;=&gt;&nbsp;</span><span class=\"string\">&quot;b\\nc&quot;</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\">&quot;a&quot;</span><span class=\"hashrocket\">&nbsp;=&gt;&nbsp;</span><span class=\"string\">&quot;b\\rc&quot;</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\">&quot;a&quot;</span><span class=\"hashrocket\">&nbsp;=&gt;&nbsp;</span><span class=\"string\">&quot;b\\tc&quot;</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\">&quot;a&quot;</span><span class=\"hashrocket\">&nbsp;=&gt;&nbsp;</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\">&quot;Hello&quot;</span>")
76
+ end
77
+
78
+ it "Formats an array" do
79
+ DataFormatter.format(["Hello", "there"]).must_equal("<span class=\"bracket\">[</span>\n&nbsp;&nbsp;<span class=\"string\">&quot;Hello&quot;</span>,\n&nbsp;&nbsp;<span class=\"string\">&quot;there&quot;</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.2
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-08-19 00:00:00.000000000 Z
11
+ date: 2014-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack