yaml_creator 0.2.0 → 0.3.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: b6f0a3e753dd5e2b9978b2fd5d273ffc720d7bc2
4
- data.tar.gz: 12cc001e15919c47aecc0dd3731fe6f8563dd4ee
3
+ metadata.gz: d1565ca1a113a6c7d4a23d4afa0649c7bd326d89
4
+ data.tar.gz: 8cf72b880eb02750d4556173559ec128c4b39064
5
5
  SHA512:
6
- metadata.gz: 97d1e1288933b81885d21c6f1c0637f45d719263ebd00947980775b735ebede15812ab2ded10d9429b8b34c5f93abb9b654afa3307e43a6fe47797e0f1485354
7
- data.tar.gz: 9a2d2274c4eb499d06070d9000328c997197cf1adfd0a9dadbbf5d3d73acd312719ec2b2f3d0c622e5584ce041624b5841dc6b5b85581843937430d70b99e50d
6
+ metadata.gz: 62639849a004fc3168fc796161cb80dd74f827ba3cadebbbd9e524a4ac0636ae592978a5b5534c86183640a89d9eb009c8f1443673c706481ba10b09a319480d
7
+ data.tar.gz: 79916b031bdbcea5b0f973dcf8cadde23dec307471fbb66a8d0ed3400ae760ccbe676ae0c3791f30789ff1536a03d329076f3ab3ecd76e517aa580765c2edeff
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 array and hash.
5
+ Create yaml file from array, hash, and json.
6
6
  This gem not use yaml lib.
7
7
 
8
8
  ## Installation
@@ -46,9 +46,15 @@ YamlCreator.from_hash('your filepath', hash)
46
46
  # YAML file from complex hash(you can use nest)
47
47
  # tab is four space string.
48
48
  # with enclosure, complex hash.
49
- YamlCreator.from_complex_hash('your filepath, hash, '"')
49
+ YamlCreator.from_complex_hash('your filepath', hash, '"')
50
50
  # without enclosure, complex hash.
51
- YamlCreator.from_complex_hash('your filepath, hash)
51
+ YamlCreator.from_complex_hash('your filepath', hash)
52
+
53
+ # YAML file from JSON
54
+ # with enclosure.
55
+ YamlCreator.from_json('your filepath', json, '"')
56
+ # without enclosure.
57
+ YamlCreator.from_json('your filepath', json)
52
58
  ```
53
59
 
54
60
  ## Development
data/lib/yaml_creator.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "yaml_creator/version"
2
2
  require "yaml_creator/parser"
3
+ require "json"
3
4
 
4
5
  # yaml creator module
5
6
  module YamlCreator
@@ -53,6 +54,20 @@ module YamlCreator
53
54
  save_file(filepath, yaml_array)
54
55
  end
55
56
 
57
+ # create yaml file from json.
58
+ # @param [String] filepath save yaml file path
59
+ # @param [Json] json json
60
+ # @param [String] enclosure enclosure character
61
+ def self.from_json(filepath, json, enclosure="")
62
+
63
+ # convert to hash.
64
+ hash = JSON.parse(json)
65
+ # create yaml array.
66
+ yaml_array = from_complex_hash(filepath, hash, enclosure)
67
+ # save file.
68
+ save_file(filepath, yaml_array)
69
+ end
70
+
56
71
  private
57
72
 
58
73
  # save yaml file.
@@ -1,3 +1,3 @@
1
1
  module YamlCreator
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/yaml_creator.gemspec CHANGED
@@ -9,8 +9,8 @@ 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.}
13
- spec.description = %q{Create yaml file from array and hash. This gem not use yaml lib.}
12
+ spec.summary = %q{Create yaml file from array, hash, and json.}
13
+ spec.description = %q{Create yaml file from array, hash, and json. This gem not use yaml lib.}
14
14
  spec.homepage = "https://github.com/koyupi/yaml_creator"
15
15
  spec.license = "MIT"
16
16
 
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.2.0
4
+ version: 0.3.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-04 00:00:00.000000000 Z
11
+ date: 2016-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: Create yaml file from array and hash. This gem not use yaml lib.
55
+ description: Create yaml file from array, hash, and json. This gem not use yaml lib.
56
56
  email:
57
57
  - corporation.ore@gmail.com
58
58
  executables: []
@@ -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, hash, and json.
100
100
  test_files: []