yaml_creator 0.3.1 → 0.3.2
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/README.md +3 -16
- data/lib/yaml_creator.rb +4 -28
- data/lib/yaml_creator/parser.rb +7 -29
- data/lib/yaml_creator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5281e154d12702c7701ae45b9401e2e85124fb62
|
|
4
|
+
data.tar.gz: 23229b43a8c0f70c12d5b8bec5cab99fd1e36276
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 010a6c032df5bf70c3f3b5a6cd3ca0ae113d51634a5b176473cac22c24d44ecc602c2b82a7bedda1c97c8c66cd11f9327e8a2c00c283148bf75c4baa6c2cc296
|
|
7
|
+
data.tar.gz: d232ca57e100186882ede3e77c2b8c727c584d6b0d916dc752d08837e633afa785eb96a62f8f120de82366bfc0f9f9219ad4dd697425f1f6e98aebe45f30b9b0
|
data/README.md
CHANGED
|
@@ -25,32 +25,19 @@ Or install it yourself as:
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
27
|
```ruby
|
|
28
|
-
# YAML file from array
|
|
28
|
+
# YAML file from array(you can use nest)
|
|
29
29
|
# with enclosure.
|
|
30
30
|
YamlCreator.from_array('your filepath', array, '"')
|
|
31
31
|
# without enclosure.
|
|
32
32
|
YamlCreator.from_array('your filepath', array)
|
|
33
33
|
|
|
34
|
-
# YAML file from
|
|
35
|
-
#
|
|
36
|
-
# with enclosure, complex array.
|
|
37
|
-
YamlCreator.from_complex_array('your filepath', array, '"')
|
|
38
|
-
# without enclosure, complex array.
|
|
39
|
-
YamlCreator.from_complex_array('your filepath', array)
|
|
40
|
-
|
|
41
|
-
# YAML file from hash
|
|
34
|
+
# YAML file from hash(you can use nest)
|
|
35
|
+
# tab is four space string.
|
|
42
36
|
# with enclosure.
|
|
43
37
|
YamlCreator.from_hash('your filepath', hash, '"')
|
|
44
38
|
# without enclosure.
|
|
45
39
|
YamlCreator.from_hash('your filepath', hash)
|
|
46
40
|
|
|
47
|
-
# YAML file from complex hash(you can use nest)
|
|
48
|
-
# tab is four space string.
|
|
49
|
-
# with enclosure, complex hash.
|
|
50
|
-
YamlCreator.from_complex_hash('your filepath', hash, '"')
|
|
51
|
-
# without enclosure, complex hash.
|
|
52
|
-
YamlCreator.from_complex_hash('your filepath', hash)
|
|
53
|
-
|
|
54
41
|
# YAML file from JSON
|
|
55
42
|
# with enclosure.
|
|
56
43
|
YamlCreator.from_json('your filepath', json, '"')
|
data/lib/yaml_creator.rb
CHANGED
|
@@ -5,32 +5,20 @@ require "json"
|
|
|
5
5
|
# yaml creator module
|
|
6
6
|
module YamlCreator
|
|
7
7
|
|
|
8
|
-
# create yaml file from array(not nest).
|
|
9
|
-
# @param [String] filepath save yaml file path
|
|
10
|
-
# @param [Array] array target array
|
|
11
|
-
# @param [String] enclosure enclosure character
|
|
12
|
-
def self.from_array(filepath, array, enclosure="")
|
|
13
|
-
|
|
14
|
-
# create yaml array.
|
|
15
|
-
yaml_array = YamlCreator::Parser.from_array(array, enclosure)
|
|
16
|
-
# save file.
|
|
17
|
-
save_file(filepath, yaml_array)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
8
|
# create yaml file from array(allow nest).
|
|
21
9
|
# array is made flatter and is made as yaml.
|
|
22
10
|
# @param [String] filepath save yaml file path
|
|
23
11
|
# @param [Array] array target array
|
|
24
12
|
# @param [String] enclosure enclosure character
|
|
25
|
-
def self.
|
|
13
|
+
def self.from_array(filepath, array, enclosure="")
|
|
26
14
|
|
|
27
15
|
# create yaml array.
|
|
28
|
-
yaml_array = YamlCreator::Parser.
|
|
16
|
+
yaml_array = YamlCreator::Parser.from_array(array, enclosure)
|
|
29
17
|
# save file.
|
|
30
18
|
save_file(filepath, yaml_array)
|
|
31
19
|
end
|
|
32
20
|
|
|
33
|
-
# create yaml file from hash(
|
|
21
|
+
# create yaml file from hash(allow nest).
|
|
34
22
|
# @param [String] filepath save yaml file path
|
|
35
23
|
# @param [Hash] hash target hash
|
|
36
24
|
# @param [String] enclosure enclosure character
|
|
@@ -42,18 +30,6 @@ module YamlCreator
|
|
|
42
30
|
save_file(filepath, yaml_array)
|
|
43
31
|
end
|
|
44
32
|
|
|
45
|
-
# create yaml file from hash(allow nest).
|
|
46
|
-
# @param [String] filepath save yaml file path
|
|
47
|
-
# @param [Hash] hash target hash
|
|
48
|
-
# @param [String] enclosure enclosure character
|
|
49
|
-
def self.from_complex_hash(filepath, hash, enclosure="")
|
|
50
|
-
|
|
51
|
-
# create yaml array.
|
|
52
|
-
yaml_array = YamlCreator::Parser.from_complex_hash(hash, enclosure)
|
|
53
|
-
# save file.
|
|
54
|
-
save_file(filepath, yaml_array)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
33
|
# create yaml file from json.
|
|
58
34
|
# @param [String] filepath save yaml file path
|
|
59
35
|
# @param [Json] json json
|
|
@@ -63,7 +39,7 @@ module YamlCreator
|
|
|
63
39
|
# convert to hash.
|
|
64
40
|
hash = JSON.parse(json)
|
|
65
41
|
# create yaml array.
|
|
66
|
-
yaml_array =
|
|
42
|
+
yaml_array = from_hash(filepath, hash, enclosure)
|
|
67
43
|
# save file.
|
|
68
44
|
save_file(filepath, yaml_array)
|
|
69
45
|
end
|
data/lib/yaml_creator/parser.rb
CHANGED
|
@@ -4,40 +4,18 @@ module YamlCreator
|
|
|
4
4
|
# parser class.
|
|
5
5
|
class Parser
|
|
6
6
|
|
|
7
|
-
# parse yaml from array.
|
|
8
|
-
# @param [Array] hash yaml array
|
|
9
|
-
# @param [String] enclosure enclosure character
|
|
10
|
-
# @return [Array] yaml array
|
|
11
|
-
def self.from_array(array, enclosure="")
|
|
12
|
-
|
|
13
|
-
# create yaml array
|
|
14
|
-
array.map { |value|
|
|
15
|
-
"- #{enclosure}#{value}#{enclosure}"
|
|
16
|
-
}
|
|
17
|
-
end
|
|
18
|
-
|
|
19
7
|
# parse yaml from array.
|
|
20
8
|
# array is made flatter and is made as yaml.
|
|
21
9
|
# @param [Array] array target array
|
|
22
10
|
# @param [String] enclosure enclosure character
|
|
23
11
|
# @return [Array] yaml array
|
|
24
|
-
def self.
|
|
12
|
+
def self.from_array(array, enclosure="")
|
|
25
13
|
|
|
26
14
|
# flatten array.
|
|
27
15
|
flatten_array = array.flatten
|
|
28
|
-
# create yaml array.
|
|
29
|
-
from_array(flatten_array, enclosure)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# parse yaml from hash.
|
|
33
|
-
# @param [Hash] hash yaml hash
|
|
34
|
-
# @param [String] enclosure enclosure character
|
|
35
|
-
# @return [Array] yaml array
|
|
36
|
-
def self.from_hash(hash, enclosure="")
|
|
37
|
-
|
|
38
16
|
# create yaml array
|
|
39
|
-
|
|
40
|
-
"
|
|
17
|
+
flatten_array.map { |value|
|
|
18
|
+
"- #{enclosure}#{value}#{enclosure}"
|
|
41
19
|
}
|
|
42
20
|
end
|
|
43
21
|
|
|
@@ -45,10 +23,10 @@ module YamlCreator
|
|
|
45
23
|
# @param [Hash] hash yaml hash
|
|
46
24
|
# @param [String] enclosure enclosure character
|
|
47
25
|
# @return [Array] yaml array
|
|
48
|
-
def self.
|
|
26
|
+
def self.from_hash(hash, enclosure="")
|
|
49
27
|
|
|
50
28
|
# create yaml array.
|
|
51
|
-
|
|
29
|
+
yaml_from_hash(hash, "", enclosure, [])
|
|
52
30
|
end
|
|
53
31
|
|
|
54
32
|
private
|
|
@@ -62,7 +40,7 @@ module YamlCreator
|
|
|
62
40
|
# @param [String] enclosure enclosure character
|
|
63
41
|
# @param [Array] yaml array
|
|
64
42
|
# @return [Array] yaml array
|
|
65
|
-
def self.
|
|
43
|
+
def self.yaml_from_hash(hash, tab_string, enclosure, yaml_array)
|
|
66
44
|
|
|
67
45
|
hash.each { |key, value|
|
|
68
46
|
# if value is Hash
|
|
@@ -71,7 +49,7 @@ module YamlCreator
|
|
|
71
49
|
yaml_array << tab_string + "#{key}:"
|
|
72
50
|
complex_tab_string = tab_string + SPACE_FOUR
|
|
73
51
|
# create yaml nest hash.
|
|
74
|
-
|
|
52
|
+
yaml_from_hash(value, complex_tab_string, enclosure, yaml_array)
|
|
75
53
|
else
|
|
76
54
|
# create yaml string.
|
|
77
55
|
yaml_array << tab_string + "#{key}: #{enclosure}#{value}#{enclosure}"
|
data/lib/yaml_creator/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yaml_creator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- h.shigemoto
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-12-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|