path_generator 0.1.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 +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +16 -0
- data/lib/path_generator.rb +26 -0
- data/path_generator.gemspec +23 -0
- data/test/.DS_Store +0 -0
- data/test/lib/path_generator_test.rb +34 -0
- data/test/test_helper.rb +3 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9efd2e06bc453055ffb6a41677f20d080cb61ef4
|
4
|
+
data.tar.gz: 155f7b15bdefba0d867db603275e7e635db635f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6148375edd7cabbf5432c6432ce91693bd893b7fed022e7b54aab15722e301db13b4cd9f62c3b14e6ef58f178ac51f7ede3f7810a41174401f59fbf6ef79eb43
|
7
|
+
data.tar.gz: 19b011664693ebc7505d93c51c34df7b08fefc57eb8231566e421df1935fe7173507552603acf3152b92322422ecd4ceb7a354fb6e0ed91aede47877712a96c6
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Gerasimos Athanasopoulos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# PathGenerator
|
2
|
+
|
3
|
+
*PathGenerator* is a microgem that generates, depth-first, paths from a Hash or an Array. Future versions will be more complete, with support for any Ruby object.
|
4
|
+
|
5
|
+
It returns an `Enumerator` so you can call any method the Ruby `Enumerator` class [supports][1].
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'path_generator'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install path_generator
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
First create an instance of the generator by passing a Hash (or Array) object
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
generator = PathGenerator.new({a: {b: [:c, {d: ""}], f: []}})
|
27
|
+
```
|
28
|
+
|
29
|
+
By calling `paths` you get back an `Enumerator` so you can work with:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
generator.paths.each { |path| p path }
|
33
|
+
# => [:a, :b, :c]
|
34
|
+
# => [:a, :b, :d]
|
35
|
+
# => [:a, :f]
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/rubymaniac/path_generator/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
Copyright (c) 2014 rubymaniac
|
49
|
+
|
50
|
+
MIT License
|
51
|
+
|
52
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
53
|
+
a copy of this software and associated documentation files (the
|
54
|
+
"Software"), to deal in the Software without restriction, including
|
55
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
56
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
57
|
+
permit persons to whom the Software is furnished to do so, subject to
|
58
|
+
the following conditions:
|
59
|
+
|
60
|
+
The above copyright notice and this permission notice shall be
|
61
|
+
included in all copies or substantial portions of the Software.
|
62
|
+
|
63
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
64
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
65
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
66
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
67
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
68
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
69
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
[1]: http://www.ruby-doc.org/core-2.1.1/Enumerator.html
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << 'lib/path_generator'
|
8
|
+
t.pattern = 'test/**/*_test.rb'
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "Open an irb session preloaded with this gem"
|
12
|
+
task :console do
|
13
|
+
sh "irb -rubygems -I lib -r path_generator.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :test
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class PathGenerator
|
2
|
+
VERSION = "0.1.0"
|
3
|
+
|
4
|
+
def initialize(obj)
|
5
|
+
@__object = obj
|
6
|
+
end
|
7
|
+
|
8
|
+
def paths
|
9
|
+
iter = lambda do |o, path, &block|
|
10
|
+
if is_empty?(o); return block.call(path) end
|
11
|
+
case o
|
12
|
+
when String, Symbol then block.call(path + [o])
|
13
|
+
when Hash then o.each { |k, v| iter.call(v, path + [k], &block) unless is_empty?(k) }
|
14
|
+
when Array then o.each { |v| iter.call(v, path, &block) unless is_empty?(v) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
Enumerator.new do |yielder|
|
18
|
+
iter.call(@__object, []) { |path| yielder.yield(path) } unless is_empty?(@__object)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def is_empty?(obj)
|
24
|
+
[[], {}, "", nil].member?(obj)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'path_generator'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "path_generator"
|
8
|
+
spec.version = PathGenerator.const_get('VERSION')
|
9
|
+
spec.authors = ["rubymaniac"]
|
10
|
+
spec.email = ["ath.ger@gmail.com"]
|
11
|
+
spec.summary = %q{PathGenerator is a microgem that generates, depth-first, paths from a structure.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/test/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path('../../test_helper.rb', __FILE__)
|
2
|
+
|
3
|
+
|
4
|
+
describe PathGenerator do
|
5
|
+
|
6
|
+
it "should generate the right paths" do
|
7
|
+
paths_hash = {
|
8
|
+
# Array configuration
|
9
|
+
[] => [],
|
10
|
+
[[], {}, nil, ""] => [],
|
11
|
+
[:a] => [[:a]],
|
12
|
+
[:a, nil, ""] => [[:a]],
|
13
|
+
[:a, :b] => [[:a], [:b]],
|
14
|
+
[:a, [:b]] => [[:a], [:b]],
|
15
|
+
[{a: []}, :b] => [[:a], [:b]],
|
16
|
+
[{a: {}}, {b: [nil, [], :d]}] => [[:a], [:b, :d]],
|
17
|
+
[{a: {}}, {b: [:c, :d]}] => [[:a], [:b, :c], [:b, :d]],
|
18
|
+
|
19
|
+
# Hash configuration
|
20
|
+
{} => [],
|
21
|
+
{ [] => "foo", nil => "bar", "" => :a } => [],
|
22
|
+
{a: nil, b: [], c: {}, d: ""} => [[:a], [:b], [:c], [:d]],
|
23
|
+
{a: {b: [], c: nil}} => [[:a, :b], [:a, :c]],
|
24
|
+
{a: {b: [:c, {d: ""}], f: []}} => [[:a, :b, :c], [:a, :b, :d], [:a, :f]],
|
25
|
+
{a: "b", "foo" => [nil, "", :b]} => [[:a, "b"], ["foo", :b]],
|
26
|
+
{a: [], b: { c: [] }} => [[:a], [:b, :c]]
|
27
|
+
}
|
28
|
+
|
29
|
+
paths_hash.each do |obj, expected|
|
30
|
+
PathGenerator.new(obj).paths.to_a.must_equal expected
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: path_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rubymaniac
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-31 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: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: ''
|
42
|
+
email:
|
43
|
+
- ath.ger@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/path_generator.rb
|
54
|
+
- path_generator.gemspec
|
55
|
+
- test/.DS_Store
|
56
|
+
- test/lib/path_generator_test.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.4.6
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: PathGenerator is a microgem that generates, depth-first, paths from a structure.
|
82
|
+
test_files:
|
83
|
+
- test/.DS_Store
|
84
|
+
- test/lib/path_generator_test.rb
|
85
|
+
- test/test_helper.rb
|