yaml_convertor 1.0.0 → 1.0.1
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.
- data/.gitignore +1 -1
- data/README.md +9 -25
- data/lib/yaml_convertor.rb +0 -1
- data/lib/yaml_convertor/version.rb +1 -1
- data/yaml_convertor.gemspec +3 -4
- metadata +6 -22
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -14,33 +14,32 @@ The resulting simple key:value hash looks like this:
|
|
14
14
|
````
|
15
15
|
{"fruit.lemon"=>"yellow", "fruit.apple.red_apples"=>"red"}
|
16
16
|
````
|
17
|
-
|
18
17
|
This works the other way around, too: if you had the simple hash; you can reconstruct the YAML hash structure.
|
19
18
|
|
20
19
|
## Installation
|
21
20
|
|
22
21
|
Add this line to your application's Gemfile:
|
23
|
-
|
22
|
+
````
|
24
23
|
gem 'yaml_convertor'
|
25
|
-
|
24
|
+
````
|
26
25
|
And then execute:
|
27
|
-
|
26
|
+
````
|
28
27
|
$ bundle
|
29
|
-
|
28
|
+
````
|
30
29
|
Or install it yourself as:
|
31
|
-
|
30
|
+
````
|
32
31
|
$ gem install yaml_convertor
|
33
|
-
|
32
|
+
````
|
34
33
|
## Usage
|
35
34
|
|
36
35
|
There are two methods you can use:
|
37
|
-
- flattener converts the structured nested YAML hash to a simple key:value
|
36
|
+
- **flattener** converts the structured nested YAML hash to a simple key:value
|
38
37
|
|
39
38
|
````
|
40
39
|
YamlConvertor.flattener(yml_hash)
|
41
40
|
````
|
42
41
|
|
43
|
-
- builder rebuilds the simple hash to a nested YAML structure
|
42
|
+
- **builder** rebuilds the simple hash to a nested YAML structure
|
44
43
|
|
45
44
|
````
|
46
45
|
YamlConvertor.builder(flat_hash)
|
@@ -48,8 +47,7 @@ YamlConvertor.builder(flat_hash)
|
|
48
47
|
|
49
48
|
## Example
|
50
49
|
|
51
|
-
Let's assume we have a YAML file called
|
52
|
-
|
50
|
+
Let's assume we have a YAML file called **file.yml**:
|
53
51
|
````
|
54
52
|
en:
|
55
53
|
errors:
|
@@ -63,15 +61,11 @@ en:
|
|
63
61
|
sessions:
|
64
62
|
signed_in: 'Signed in successfully.'
|
65
63
|
````
|
66
|
-
|
67
64
|
We open this file using Psych (Ruby's YAML parser), and it will return a nested YAML hash structure
|
68
|
-
|
69
65
|
````ruby
|
70
66
|
yml_hash = Psych.load_file('file.yml')
|
71
67
|
````
|
72
|
-
|
73
68
|
yml_hash looks like this:
|
74
|
-
|
75
69
|
````
|
76
70
|
{"en"=>{
|
77
71
|
"errors"=>{
|
@@ -86,15 +80,11 @@ yml_hash looks like this:
|
|
86
80
|
}
|
87
81
|
}
|
88
82
|
````
|
89
|
-
|
90
83
|
Now! If we use flattener:
|
91
|
-
|
92
84
|
````
|
93
85
|
flat_hash = YamlConvertor.flattener(yml_hash)
|
94
86
|
````
|
95
|
-
|
96
87
|
flat_hash will look like this:
|
97
|
-
|
98
88
|
````
|
99
89
|
{
|
100
90
|
"en.errors.messages.not_locked"=>"was not locked",
|
@@ -108,14 +98,11 @@ flat_hash will look like this:
|
|
108
98
|
|
109
99
|
Now let's assume we have a flat hash and we want to rebuild it to a YAML file.
|
110
100
|
Here's our flat_hash from our example above:
|
111
|
-
|
112
101
|
````ruby
|
113
102
|
flat_hash = {"en.errors.messages.not_locked"=>"was not locked", "en.errors.messages.not_saved.other"=>"other error", "en.devise.failure.already_authenticated"=>"You are already signed in.", "en.devise.sessions.signed_in"=>"Signed in successfully."}
|
114
|
-
|
115
103
|
nested_hash = YamlConvertor.builder(flat_hash)
|
116
104
|
````
|
117
105
|
nested_hash is now:
|
118
|
-
|
119
106
|
````
|
120
107
|
{"en"=>{
|
121
108
|
"errors"=>{
|
@@ -130,13 +117,10 @@ nested_hash is now:
|
|
130
117
|
}
|
131
118
|
}
|
132
119
|
````
|
133
|
-
|
134
120
|
Dump it with Pysch..
|
135
|
-
|
136
121
|
````ruby
|
137
122
|
Psych.dump(nested_hash)
|
138
123
|
````
|
139
|
-
|
140
124
|
The output will be:
|
141
125
|
````
|
142
126
|
---
|
data/lib/yaml_convertor.rb
CHANGED
data/yaml_convertor.gemspec
CHANGED
@@ -4,9 +4,9 @@ require File.expand_path('../lib/yaml_convertor/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Nour"]
|
6
6
|
gem.email = ["nour.fwh@gmail.com"]
|
7
|
-
gem.description = %q{yaml_convertor converts YAML structure to
|
8
|
-
gem.summary = %q{YAML to
|
9
|
-
gem.homepage = ""
|
7
|
+
gem.description = %q{yaml_convertor converts YAML hash structure to simple key:value }
|
8
|
+
gem.summary = %q{YAML to simple key:value hash}
|
9
|
+
gem.homepage = "https://rubygems.org/gems/yaml_convertor"
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -16,7 +16,6 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = YamlConvertor::VERSION
|
17
17
|
|
18
18
|
gem.add_development_dependency 'rake'
|
19
|
-
gem.add_development_dependency 'rb-readline'
|
20
19
|
gem.add_development_dependency 'test-unit'
|
21
20
|
gem.add_runtime_dependency 'psych', '1.3.4'
|
22
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_convertor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rb-readline
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
31
|
name: test-unit
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,7 +59,7 @@ dependencies:
|
|
75
59
|
- - '='
|
76
60
|
- !ruby/object:Gem::Version
|
77
61
|
version: 1.3.4
|
78
|
-
description: ! 'yaml_convertor converts YAML structure to
|
62
|
+
description: ! 'yaml_convertor converts YAML hash structure to simple key:value '
|
79
63
|
email:
|
80
64
|
- nour.fwh@gmail.com
|
81
65
|
executables: []
|
@@ -92,7 +76,7 @@ files:
|
|
92
76
|
- test/devise.en.yml
|
93
77
|
- test/test_convertor.rb
|
94
78
|
- yaml_convertor.gemspec
|
95
|
-
homepage:
|
79
|
+
homepage: https://rubygems.org/gems/yaml_convertor
|
96
80
|
licenses: []
|
97
81
|
post_install_message:
|
98
82
|
rdoc_options: []
|
@@ -106,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
90
|
version: '0'
|
107
91
|
segments:
|
108
92
|
- 0
|
109
|
-
hash:
|
93
|
+
hash: 204075919
|
110
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
95
|
none: false
|
112
96
|
requirements:
|
@@ -115,13 +99,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
99
|
version: '0'
|
116
100
|
segments:
|
117
101
|
- 0
|
118
|
-
hash:
|
102
|
+
hash: 204075919
|
119
103
|
requirements: []
|
120
104
|
rubyforge_project:
|
121
105
|
rubygems_version: 1.8.24
|
122
106
|
signing_key:
|
123
107
|
specification_version: 3
|
124
|
-
summary: YAML to
|
108
|
+
summary: YAML to simple key:value hash
|
125
109
|
test_files:
|
126
110
|
- test/devise.en.yml
|
127
111
|
- test/test_convertor.rb
|