immosquare-extensions 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/immosquare-extensions/hash.rb +18 -1
- data/lib/immosquare-extensions/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b217c241e856d71b6c96c67abbf74eab8ba153d99c50074913ad2ca1e21fd491
|
4
|
+
data.tar.gz: c5c57c09e32e6f1a8170337875bb4affbac7697bbf756ce1005fccbcb0036f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a121695c0a02bca0919b5e7f0d7e9eb72aa808845fa4f25fa053b96455e426e2bec41db3e79d3f6a32520931d2cb483df00fb3a99170920067a4475d9b132c8
|
7
|
+
data.tar.gz: e1c27fb282f8d7a5745b04505a9de591de4ad3b8270717206aa7dbb5bda89f1a66e676ec3b5f5311d6522ecbb1d2c5681c13d9b7e13d8e0e552fcde822ad8c27
|
@@ -124,11 +124,22 @@ class Hash
|
|
124
124
|
if hash.is_a?(Hash)
|
125
125
|
return "{}" if hash.empty?
|
126
126
|
|
127
|
+
if hash.keys.count == 1
|
128
|
+
key, value = hash.first
|
129
|
+
value_str = json_representation(value, align, indent_size, indent)
|
130
|
+
return "{\"#{key}\": #{value_str}}"
|
131
|
+
end
|
132
|
+
|
127
133
|
max_key_length = align ? hash.keys.map(&:to_s).map(&:length).max : 0
|
128
134
|
|
129
135
|
json_parts = hash.map do |key, value|
|
130
136
|
value_str = json_representation(value, align, indent_size, indent)
|
131
|
-
spacing =
|
137
|
+
spacing =
|
138
|
+
if value.is_a?(Hash)
|
139
|
+
space
|
140
|
+
else
|
141
|
+
align ? space * (max_key_length - key.to_s.length + 1) : space
|
142
|
+
end
|
132
143
|
"#{space * (indent + indent_size)}\"#{key}\":#{spacing}#{value_str}"
|
133
144
|
end
|
134
145
|
|
@@ -136,6 +147,11 @@ class Hash
|
|
136
147
|
elsif hash.is_a?(Array)
|
137
148
|
return "[]" if hash.empty?
|
138
149
|
|
150
|
+
if hash.length == 1
|
151
|
+
value_str = json_representation(hash.first, align, indent_size, indent)
|
152
|
+
return "[#{value_str}]"
|
153
|
+
end
|
154
|
+
|
139
155
|
array_parts = hash.map do |value|
|
140
156
|
"#{space * (indent + indent_size)}#{json_representation(value, align, indent_size, indent)}"
|
141
157
|
end
|
@@ -143,4 +159,5 @@ class Hash
|
|
143
159
|
end
|
144
160
|
end
|
145
161
|
|
162
|
+
|
146
163
|
end
|