immosquare-extensions 0.1.5 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- 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: 94018ffd0ddd54cf8ee8914f26b0724424698f94e0bbcd008dbdba480580bdca
|
4
|
+
data.tar.gz: a3f004b8721b0e722ecd9b20c3aac54586ac0da7a44f289e6791169c4c40b754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b919e5f6e13c1759ad5f694fc0db3c07cd38c89b98db90482a70fe5f672c758e1d0b004435689967ff382234a1cdfa562f36906355e5df02b8d1787eb162e4cd
|
7
|
+
data.tar.gz: 8270ffd69a4cf5823996d9c58e8290bf82244e46dec58cd8ba4884d3ac4b8b6533508220cd58bfcb064948c3ec4b0abf30574677ee1d908f6eca9258d8c615db
|
@@ -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 && indent > 0
|
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 && !hash.first.is_a?(Hash)
|
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
|