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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f4139a986ed8d81eb503ec5bd8400d8f7d9817d
4
- data.tar.gz: dcc5a8d2be12e3cf8cd97dcff519f804bc7ceef2
3
+ metadata.gz: b6f0a3e753dd5e2b9978b2fd5d273ffc720d7bc2
4
+ data.tar.gz: 12cc001e15919c47aecc0dd3731fe6f8563dd4ee
5
5
  SHA512:
6
- metadata.gz: ffcbd874f1dc9c7ad11174a2aea453984bc3e6cd9b02fd0512b7291f36f4ef8bae49f0896b1a96acf3814694376964f113c00a6668a02404af2257dc5bfe99ff
7
- data.tar.gz: f62f710b9fc6ddf876c4486e8b454b78d37cb681294ac5fd75292c58018b9b7922f176bf53755b7fe6fa05ba6487f49bd44793857b096a43c637819fdd994731
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 simple array and hash.
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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module YamlCreator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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. This gem not use yaml lib.}
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.1.1
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-01 00:00:00.000000000 Z
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. This gem not use yaml lib.
99
+ summary: Create yaml file from array and hash.
100
100
  test_files: []