hash_array_flatten 0.1.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 +7 -0
- data/.github/workflows/ruby.yml +20 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +25 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hash_array_flatten.gemspec +31 -0
- data/lib/hash_array_flatten.rb +19 -0
- data/lib/hash_array_flatten/version.rb +3 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b617fe3d473b3073f434ed07306c78c829b77baa1d883e5873e2b6b76a9e5da6
|
|
4
|
+
data.tar.gz: 944283f838e11f332fe6dd4a5b33061b136d2dfcdaee71f34b54b292e44486e9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ef03aa575ca56dc21ce7b202ec82e3d9754948121d7c5e82e965e5d69aabeae91e27d7354cb9ddabee1d6a685f73ecd66e75591bb0c778d4057b8e41b51e72f2
|
|
7
|
+
data.tar.gz: 94a93d0a4ffa95eb18f8954124256f45ca71074559238251d6b7690bbc8937c42637ce438c5dce217ef889634e332674715e0db901cecdb622f24de42457ac15
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v1
|
|
12
|
+
- name: Set up Ruby 2.6
|
|
13
|
+
uses: actions/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby-version: 2.6.x
|
|
16
|
+
- name: Build and test with Rspec
|
|
17
|
+
run: |
|
|
18
|
+
gem install bundler
|
|
19
|
+
bundle install --jobs 4 --retry 3
|
|
20
|
+
bundle exec rspec
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# HashArrayFlatten
|
|
2
|
+
|
|
3
|
+
Flatten nested hash with arrays into single level.
|
|
4
|
+
|
|
5
|
+
https://rubygems.org/gems/hash_array_flatten
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
### Nested hash
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
HashArrayFlatten.visit({"a" => {"x" => 1, "y" => 2}})
|
|
13
|
+
# => {"a.x"=>1, "a.y"=>2}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Nested hash with array
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
HashArrayFlatten.visit({"a" => {"aa" => 1, "ab" => 2}, "b" => [100, 200, {"c" => 300}]})
|
|
20
|
+
# => {"a.aa"=>1, "a.ab"=>2, "b.0"=>100, "b.1"=>200, "b.2.c"=>300}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "hash_array_flatten"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
require "hash_array_flatten/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "hash_array_flatten"
|
|
7
|
+
spec.version = HashArrayFlatten::VERSION
|
|
8
|
+
spec.authors = ["Takahiko Inayama"]
|
|
9
|
+
spec.email = ["sagittariusm25@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Flatten nested hash with arrays into single level."
|
|
12
|
+
spec.description = "Flatten nested hash with arrays into single level."
|
|
13
|
+
spec.homepage = "https://github.com/TETRA2000/hash_array_flatten/"
|
|
14
|
+
|
|
15
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
16
|
+
spec.metadata["source_code_uri"] = "https://github.com/TETRA2000/hash_array_flatten/"
|
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/TETRA2000/hash_array_flatten/releases"
|
|
18
|
+
|
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
21
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
23
|
+
end
|
|
24
|
+
spec.bindir = "exe"
|
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
26
|
+
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
31
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require "hash_array_flatten/version"
|
|
2
|
+
|
|
3
|
+
module HashArrayFlatten
|
|
4
|
+
def self.visit(data, current_key = nil, result = {})
|
|
5
|
+
if data.is_a?(Hash)
|
|
6
|
+
data.keys.map {|key| visit(data[key], [current_key,
|
|
7
|
+
key].compact.join("."), result)}
|
|
8
|
+
elsif data.is_a?(Array)
|
|
9
|
+
# TODO refactor
|
|
10
|
+
converted = data.map.with_index.inject({}){|hash, (v, i)| hash[i] = v; hash }
|
|
11
|
+
converted.keys.map {|key| visit(converted[key], [current_key,
|
|
12
|
+
key].compact.join("."), result)}
|
|
13
|
+
else
|
|
14
|
+
result[current_key] = data
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
result
|
|
18
|
+
end
|
|
19
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hash_array_flatten
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Takahiko Inayama
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-08-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '2.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '2.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description: Flatten nested hash with arrays into single level.
|
|
56
|
+
email:
|
|
57
|
+
- sagittariusm25@gmail.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".github/workflows/ruby.yml"
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- ".rspec"
|
|
65
|
+
- ".travis.yml"
|
|
66
|
+
- Gemfile
|
|
67
|
+
- README.md
|
|
68
|
+
- Rakefile
|
|
69
|
+
- bin/console
|
|
70
|
+
- bin/setup
|
|
71
|
+
- hash_array_flatten.gemspec
|
|
72
|
+
- lib/hash_array_flatten.rb
|
|
73
|
+
- lib/hash_array_flatten/version.rb
|
|
74
|
+
homepage: https://github.com/TETRA2000/hash_array_flatten/
|
|
75
|
+
licenses: []
|
|
76
|
+
metadata:
|
|
77
|
+
homepage_uri: https://github.com/TETRA2000/hash_array_flatten/
|
|
78
|
+
source_code_uri: https://github.com/TETRA2000/hash_array_flatten/
|
|
79
|
+
changelog_uri: https://github.com/TETRA2000/hash_array_flatten/releases
|
|
80
|
+
post_install_message:
|
|
81
|
+
rdoc_options: []
|
|
82
|
+
require_paths:
|
|
83
|
+
- lib
|
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ">="
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
94
|
+
requirements: []
|
|
95
|
+
rubyforge_project:
|
|
96
|
+
rubygems_version: 2.7.6
|
|
97
|
+
signing_key:
|
|
98
|
+
specification_version: 4
|
|
99
|
+
summary: Flatten nested hash with arrays into single level.
|
|
100
|
+
test_files: []
|