scrawl 2.0.0 → 2.1.0

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: 51f49457e302b9c0332607ec11823a28e2e79c2a
4
- data.tar.gz: 24c3bbfe67bf1735272b29794b03cd0362e13831
3
+ metadata.gz: 1fae72114f1a7396cc0e541f34ab73c3e005af43
4
+ data.tar.gz: edf0916f009bd56ec5a8225aaf086d8de5326b93
5
5
  SHA512:
6
- metadata.gz: 6e0f7c6228413eee997cd4eddf79657d1e440e1bc54a7532feb35515c1795a6ed20ed4eef23def92059ee0479cee5ae1e2dae48564394f71ea3e458006818786
7
- data.tar.gz: a398998d1a96fb411b9798eddf5872dec657ca7cc962a3ffb8a9e530fc7493630ab3ec4fa412e95afce31347dca4eee2332eaf9e06ec335ed608850a34c550cf
6
+ metadata.gz: ae0b61376227d10149e3f7fef6289344748c06293202ed03028672b24248ce925bfeee6186f1fb0b5747b77888bd2b29c2ee9aaca8956789bdb350768349ce11
7
+ data.tar.gz: 03e82b8abc0c119748b305f448f9bb2ecda76419afa2696d28b0d638325c028773396c1b5b411d015078fe87bc003bc0d96f95d06a9a56f307b08a446862ed6b
@@ -17,10 +17,13 @@ class Scrawl
17
17
 
18
18
  def inspect(namespace = nil)
19
19
  @tree.map do |key, value|
20
- unless value.respond_to?(:to_hash)
21
- label(namespace, key) + KEY_VALUE_DELIMITER + element(value)
22
- else
20
+ case
21
+ when value.kind_of?(Hash) && value.none?
22
+ label(namespace, key) + KEY_VALUE_DELIMITER + element(nil)
23
+ when value.respond_to?(:to_hash)
23
24
  Scrawl.new(value).inspect(key)
25
+ else
26
+ label(namespace, key) + KEY_VALUE_DELIMITER + element(value)
24
27
  end
25
28
  end.join(PAIR_DELIMITER)
26
29
  end
@@ -1,3 +1,3 @@
1
1
  class Scrawl
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -41,10 +41,6 @@ RSpec.describe Scrawl do
41
41
  context "scrawl objects" do
42
42
  let(:trees) { [Scrawl.new(a: 1), Scrawl.new(b: 2)] }
43
43
  end
44
-
45
- context "hash and scrawl objects" do
46
-
47
- end
48
44
  end
49
45
  end
50
46
 
@@ -84,41 +80,55 @@ RSpec.describe Scrawl do
84
80
  let(:input) { { a: "example" } }
85
81
 
86
82
  it "includes the escaped text" do
87
- expect(inspect).to include("\"example\"")
83
+ expect(inspect).to eq("a=\"example\"")
88
84
  end
89
85
  end
90
86
 
91
87
  context "and a proc value" do
92
- let(:input) { { a: -> { "example#{rand(1..10_000)}" } } }
88
+ let(:input) { { a: -> { "example#{1 + 1}" } } }
93
89
 
94
90
  it "evaluate the proc" do
95
- expect(inspect).to include("example")
91
+ expect(inspect).to eq("a=\"example2\"")
96
92
  end
97
93
 
98
- it "never stores the value" do
99
- first = scrawl.inspect
100
- second = scrawl.inspect
101
- expect(first).to_not eq(second)
94
+ context "with a random portion" do
95
+ let(:input) { { a: -> { "example#{rand(1..100000)}" } } }
96
+
97
+ it "never stores the value" do
98
+ first = scrawl.inspect
99
+ second = scrawl.inspect
100
+ expect(first).to_not eq(second)
101
+ end
102
102
  end
103
103
  end
104
104
 
105
105
  context "and a number value" do
106
106
  it "returns just the number" do
107
- expect(inspect).to include("=1")
107
+ expect(inspect).to eq("a=1")
108
108
  end
109
109
  end
110
110
 
111
111
  context "and a symbol value" do
112
112
  let(:input) { { a: :example } }
113
+
113
114
  it "returns the escaped string equivelent" do
114
- expect(inspect).to include("\"example\"")
115
+ expect(inspect).to eq("a=\"example\"")
115
116
  end
116
117
  end
117
118
 
118
119
  context "and a regexp value" do
119
120
  let(:input) { { a: /foo(.+)/ } }
121
+
120
122
  it "returns the escaped regexp" do
121
- expect(inspect).to include("/foo(.+)/")
123
+ expect(inspect).to eq("a=/foo(.+)/")
124
+ end
125
+ end
126
+
127
+ context "and a hash" do
128
+ let(:input) { { a: Hash.new } }
129
+
130
+ it "returns as if nil" do
131
+ expect(inspect).to eq("a=nil")
122
132
  end
123
133
  end
124
134
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrawl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kurtis Rainbolt-Greene