yaml_creator 0.1.1 → 0.2.0
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 +8 -1
- data/lib/yaml_creator.rb +12 -0
- data/lib/yaml_creator/parser.rb +40 -0
- data/lib/yaml_creator/version.rb +1 -1
- data/yaml_creator.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b6f0a3e753dd5e2b9978b2fd5d273ffc720d7bc2
|
|
4
|
+
data.tar.gz: 12cc001e15919c47aecc0dd3731fe6f8563dd4ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97d1e1288933b81885d21c6f1c0637f45d719263ebd00947980775b735ebede15812ab2ded10d9429b8b34c5f93abb9b654afa3307e43a6fe47797e0f1485354
|
|
7
|
+
data.tar.gz: 9a2d2274c4eb499d06070d9000328c997197cf1adfd0a9dadbbf5d3d73acd312719ec2b2f3d0c622e5584ce041624b5841dc6b5b85581843937430d70b99e50d
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yaml_creator`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
4
|
|
|
5
|
-
Create yaml file from
|
|
5
|
+
Create yaml file from array and hash.
|
|
6
6
|
This gem not use yaml lib.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
@@ -42,6 +42,13 @@ YamlCreator.from_complex_array('your filepath', array)
|
|
|
42
42
|
YamlCreator.from_hash('your filepath', hash, '"')
|
|
43
43
|
# without enclosure.
|
|
44
44
|
YamlCreator.from_hash('your filepath', hash)
|
|
45
|
+
|
|
46
|
+
# YAML file from complex hash(you can use nest)
|
|
47
|
+
# tab is four space string.
|
|
48
|
+
# with enclosure, complex hash.
|
|
49
|
+
YamlCreator.from_complex_hash('your filepath, hash, '"')
|
|
50
|
+
# without enclosure, complex hash.
|
|
51
|
+
YamlCreator.from_complex_hash('your filepath, hash)
|
|
45
52
|
```
|
|
46
53
|
|
|
47
54
|
## Development
|
data/lib/yaml_creator.rb
CHANGED
|
@@ -41,6 +41,18 @@ module YamlCreator
|
|
|
41
41
|
save_file(filepath, yaml_array)
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
# create yaml file from hash(allow nest).
|
|
45
|
+
# @param [String] filepath save yaml file path
|
|
46
|
+
# @param [Hash] hash target hash
|
|
47
|
+
# @param [String] enclosure enclosure character
|
|
48
|
+
def self.from_complex_hash(filepath, hash, enclosure="")
|
|
49
|
+
|
|
50
|
+
# create yaml array.
|
|
51
|
+
yaml_array = YamlCreator::Parser.from_complex_hash(hash, enclosure)
|
|
52
|
+
# save file.
|
|
53
|
+
save_file(filepath, yaml_array)
|
|
54
|
+
end
|
|
55
|
+
|
|
44
56
|
private
|
|
45
57
|
|
|
46
58
|
# save yaml file.
|
data/lib/yaml_creator/parser.rb
CHANGED
|
@@ -40,5 +40,45 @@ module YamlCreator
|
|
|
40
40
|
"#{key}: #{enclosure}#{value}#{enclosure}"
|
|
41
41
|
}
|
|
42
42
|
end
|
|
43
|
+
|
|
44
|
+
# parse yaml from hash.
|
|
45
|
+
# @param [Hash] hash yaml hash
|
|
46
|
+
# @param [String] enclosure enclosure character
|
|
47
|
+
# @return [Array] yaml array
|
|
48
|
+
def self.from_complex_hash(hash, enclosure="")
|
|
49
|
+
|
|
50
|
+
# create yaml array.
|
|
51
|
+
yaml_from_complex_hash(hash, "", enclosure, [])
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
# tab string, four space.
|
|
57
|
+
SPACE_FOUR = " "
|
|
58
|
+
|
|
59
|
+
# parse yaml from complex hash.
|
|
60
|
+
# @param [Hash] hash yaml hash
|
|
61
|
+
# @param [String] tab_string tab string, default space(length = 4)
|
|
62
|
+
# @param [String] enclosure enclosure character
|
|
63
|
+
# @param [Array] yaml array
|
|
64
|
+
# @return [Array] yaml array
|
|
65
|
+
def self.yaml_from_complex_hash(hash, tab_string, enclosure, yaml_array)
|
|
66
|
+
|
|
67
|
+
hash.each { |key, value|
|
|
68
|
+
# if value is Hash
|
|
69
|
+
if value.is_a?(Hash)
|
|
70
|
+
# create yaml key string.
|
|
71
|
+
yaml_array << tab_string + "#{key}:"
|
|
72
|
+
complex_tab_string = tab_string + SPACE_FOUR
|
|
73
|
+
# create yaml nest hash.
|
|
74
|
+
yaml_from_complex_hash(value, complex_tab_string, enclosure, yaml_array)
|
|
75
|
+
else
|
|
76
|
+
# create yaml string.
|
|
77
|
+
yaml_array << tab_string + "#{key}: #{enclosure}#{value}#{enclosure}"
|
|
78
|
+
end
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
yaml_array
|
|
82
|
+
end
|
|
43
83
|
end
|
|
44
84
|
end
|
data/lib/yaml_creator/version.rb
CHANGED
data/yaml_creator.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["h.shigemoto"]
|
|
10
10
|
spec.email = ["corporation.ore@gmail.com"]
|
|
11
11
|
|
|
12
|
-
spec.summary = %q{Create yaml file from array and hash.
|
|
12
|
+
spec.summary = %q{Create yaml file from array and hash.}
|
|
13
13
|
spec.description = %q{Create yaml file from array and hash. This gem not use yaml lib.}
|
|
14
14
|
spec.homepage = "https://github.com/koyupi/yaml_creator"
|
|
15
15
|
spec.license = "MIT"
|
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.
|
|
4
|
+
version: 0.2.0
|
|
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-
|
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -96,5 +96,5 @@ rubyforge_project:
|
|
|
96
96
|
rubygems_version: 2.6.6
|
|
97
97
|
signing_key:
|
|
98
98
|
specification_version: 4
|
|
99
|
-
summary: Create yaml file from array and hash.
|
|
99
|
+
summary: Create yaml file from array and hash.
|
|
100
100
|
test_files: []
|