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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ca65651f069d3d7c1818b5ca31c1d40536465f41cc1bebaaee9a5da968160aa
4
- data.tar.gz: 732c0b2ddabe7594bc72c748b91b74476de533690d3e69095a432b3fe8bc0c3c
3
+ metadata.gz: 03d673fe8dd0ed934707ea895618dbdd21284004d04c299370b17a02ffbe6699
4
+ data.tar.gz: 60dd30b98fe417f0090584dc2d8831003c0f9e9c677f87fccf7ff668a5549204
5
5
  SHA512:
6
- metadata.gz: 31290e9b62b0490749a4816ce1f9bc0a8da7fd2bad34570140b451c5a01466d57a142ff9a7833a7aab2edc04034559a6cd923ecc4dd516e5531a90961414278a
7
- data.tar.gz: 2bea9806043385131a6b584bf011112dc180afd0e3d2c32a8ed8b99bb9c73b009a934df7c5066322e4b4e39f00b1fc7fa9afc57a5cb0fe0a142cdacf1b0c3ef8
6
+ metadata.gz: d96ab1bf6ca61f546416912188f3df246a637cf835b41e5fb49b254c2528a0a6486668ed19ff481658c463b4b9fa2aba0c502ce2ff0ea565f0f7c3e78324ffa3
7
+ data.tar.gz: 34721ecacc323854bc0dd87634d29cf63694760ae04a822d7bbb9d052431889a1fd2c09c4a41b66b3e25a20c120aa4772210abf9bfbc4f18d5f1528f7555fb30
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- to_simple_yaml (1.0.5)
4
+ to_simple_yaml (1.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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) && obj[key].start_with?('#', '*')
29
- yaml << template("#{array_first ? '- ' : ''}#{key}: '#{obj[key]}'", array_inline ? indent + 1 : indent)
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) && value.start_with?('#', '*')
47
- yaml << template("- '#{value}'", indent)
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
 
@@ -1,3 +1,3 @@
1
1
  module ToSimpleYaml
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_simple_yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - tanmen