to_simple_yaml 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/to_simple_yaml/core.rb +14 -14
- data/lib/to_simple_yaml/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: 03d673fe8dd0ed934707ea895618dbdd21284004d04c299370b17a02ffbe6699
|
4
|
+
data.tar.gz: 60dd30b98fe417f0090584dc2d8831003c0f9e9c677f87fccf7ff668a5549204
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d96ab1bf6ca61f546416912188f3df246a637cf835b41e5fb49b254c2528a0a6486668ed19ff481658c463b4b9fa2aba0c502ce2ff0ea565f0f7c3e78324ffa3
|
7
|
+
data.tar.gz: 34721ecacc323854bc0dd87634d29cf63694760ae04a822d7bbb9d052431889a1fd2c09c4a41b66b3e25a20c120aa4772210abf9bfbc4f18d5f1528f7555fb30
|
data/Gemfile.lock
CHANGED
data/lib/to_simple_yaml/core.rb
CHANGED
@@ -25,17 +25,13 @@ class Object
|
|
25
25
|
obj.compact.keys.each_with_index do |key, index|
|
26
26
|
array_first = array && index == 0
|
27
27
|
array_inline = array && index != 0
|
28
|
-
if obj[key].is_a?(String)
|
29
|
-
yaml << template("#{array_first ? '- ' : ''}#{key}:
|
30
|
-
elsif obj[key].is_a?(String) || obj[key].is_a?(Numeric) || obj[key].is_a?(TrueClass) || obj[key].is_a?(FalseClass)
|
31
|
-
yaml << template("#{array_first ? '- ' : ''}#{key}: #{obj[key]}", array_inline ? indent + 1 : indent)
|
32
|
-
elsif obj[key].is_a?(Symbol)
|
33
|
-
yaml << template("#{array_first ? '- ' : ''}#{key}: #{obj[key].to_s}", array_inline ? indent + 1 : indent)
|
28
|
+
if obj[key].is_a?(String) || obj[key].is_a?(Symbol) || obj[key].is_a?(Numeric) || obj[key].is_a?(TrueClass) || obj[key].is_a?(FalseClass)
|
29
|
+
yaml << template("#{array_first ? '- ' : ''}#{text(key)}: #{text(obj[key])}", array_inline ? indent + 1 : indent)
|
34
30
|
elsif obj[key].is_a?(Array)
|
35
|
-
yaml << template("#{array_first ? '- ' : ''}#{key}:", array_inline ? indent + 1 : indent)
|
31
|
+
yaml << template("#{array_first ? '- ' : ''}#{text(key)}:", array_inline ? indent + 1 : indent)
|
36
32
|
yaml << generate_yaml(obj[key], indent: array_inline ? indent + 2 : indent + 1)
|
37
33
|
else
|
38
|
-
yaml << template("#{array_first ? '- ' : ''}#{key}:", array_inline ? indent + 1 : indent)
|
34
|
+
yaml << template("#{array_first ? '- ' : ''}#{text(key)}:", array_inline ? indent + 1 : indent)
|
39
35
|
yaml << generate_yaml(obj[key], indent: array_inline || array_first ? indent + 2 : indent + 1)
|
40
36
|
end
|
41
37
|
end
|
@@ -43,12 +39,8 @@ class Object
|
|
43
39
|
elsif obj.is_a?(Array)
|
44
40
|
yaml = ''
|
45
41
|
obj.compact.each do |value|
|
46
|
-
if value.is_a?(String)
|
47
|
-
yaml << template("-
|
48
|
-
elsif value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
49
|
-
yaml << template("- #{value}", indent)
|
50
|
-
elsif value.is_a?(Symbol)
|
51
|
-
yaml << template("- #{value.to_s}", indent)
|
42
|
+
if value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(Numeric) || value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
43
|
+
yaml << template("- #{text(value)}", indent)
|
52
44
|
elsif value.is_a?(Array)
|
53
45
|
yaml << template('-', indent)
|
54
46
|
yaml << generate_yaml(value, indent: indent + 1)
|
@@ -67,5 +59,13 @@ class Object
|
|
67
59
|
def template(value, indent)
|
68
60
|
"#{[].fill(' ', 0...indent).join('')}#{value}\n"
|
69
61
|
end
|
62
|
+
|
63
|
+
def text(value)
|
64
|
+
if value.to_s.start_with?('#', '*')
|
65
|
+
"'#{value}'"
|
66
|
+
else
|
67
|
+
value
|
68
|
+
end
|
69
|
+
end
|
70
70
|
end
|
71
71
|
|