recurator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +10 -0
- data/lib/recurator/version.rb +3 -0
- data/lib/recurator.bundle +0 -0
- data/lib/recurator.rb +49 -0
- data/recurator.gemspec +24 -0
- data/spec/helper.rb +2 -0
- data/spec/recurator_spec.rb +33 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8d91922d6a4571ec2efad5e92de14b23f27fd776
|
4
|
+
data.tar.gz: 8db2aa655e17fe33a8e6efeb3b170b09dac620d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 25a398f1ebd16af4714ca75b546b772f541910f311fcb223c99f670d688d6495d29931e6a1fbb81f25af576a31d7abb39e77aadb2391867525bc42c3283e17d9
|
7
|
+
data.tar.gz: 1c80847c3ec3b24f9ccd2073584ab1dc6b4cea44bb5cbb91b10c094dae5b2ea8111c5672babbc4436cf71761705127e9bd5ce5bc5fb6cfbaf0f8c7af23613b71
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 ksss
|
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,30 @@
|
|
1
|
+
# Recurator
|
2
|
+
|
3
|
+
Recurator is object for recursive processing like Enumeator.
|
4
|
+
|
5
|
+
Recurator is included `Enumeable` module.
|
6
|
+
|
7
|
+
## Synopsis
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
obj = {
|
11
|
+
"one" => {
|
12
|
+
"two" => [1,2,3],
|
13
|
+
"three" => "foo",
|
14
|
+
"four" => {
|
15
|
+
"five" => {}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
19
|
+
recur = Recurator.new obj # or obj.to_recur
|
20
|
+
|
21
|
+
p recur.values.grep(Hash)
|
22
|
+
#=> [{"two" => [1,2,3],"three" => "foo","four" => {"five" => {}}}, {"five" => {}}, {}]
|
23
|
+
|
24
|
+
p recur.keys
|
25
|
+
#=> ["one", "two", "three", "four", "five"]
|
26
|
+
```
|
27
|
+
|
28
|
+
## Install
|
29
|
+
|
30
|
+
gem install recurator
|
data/Rakefile
ADDED
Binary file
|
data/lib/recurator.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
class Recurator
|
2
|
+
include Enumerable
|
3
|
+
|
4
|
+
def initialize (obj)
|
5
|
+
@obj = obj
|
6
|
+
end
|
7
|
+
|
8
|
+
def each
|
9
|
+
looper = lambda { |o|
|
10
|
+
case o
|
11
|
+
when Array
|
12
|
+
o.each_with_index {|i, index|
|
13
|
+
yield [index, i]
|
14
|
+
looper.call(i)
|
15
|
+
}
|
16
|
+
when Hash
|
17
|
+
o.each { |key, value|
|
18
|
+
yield [key, value]
|
19
|
+
looper.call(value)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
}
|
23
|
+
|
24
|
+
if block_given?
|
25
|
+
looper.call(@obj)
|
26
|
+
else
|
27
|
+
self.to_enum
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def keys
|
32
|
+
map { |key, value| key }
|
33
|
+
end
|
34
|
+
|
35
|
+
def values
|
36
|
+
map { |key, value| value }
|
37
|
+
end
|
38
|
+
|
39
|
+
def flatten
|
40
|
+
ret = []
|
41
|
+
each { |key, value|
|
42
|
+
ret << key
|
43
|
+
if !value.kind_of?(Array) && !value.kind_of?(Hash)
|
44
|
+
ret << value
|
45
|
+
end
|
46
|
+
}
|
47
|
+
ret
|
48
|
+
end
|
49
|
+
end
|
data/recurator.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'recurator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "recurator"
|
8
|
+
spec.version = Recurator::VERSION
|
9
|
+
spec.author = "ksss"
|
10
|
+
spec.email = ["co000ri@gmail.com"]
|
11
|
+
spec.description = %q{Recurator is object for recursive processing like Enumeator.}
|
12
|
+
spec.summary = %q{Recurator is object for recursive processing like Enumeator.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.11"
|
24
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Recurator do
|
4
|
+
let :recur do
|
5
|
+
Recurator.new({
|
6
|
+
"one" => {
|
7
|
+
"two" => {
|
8
|
+
"three" => 3
|
9
|
+
}
|
10
|
+
}
|
11
|
+
})
|
12
|
+
end
|
13
|
+
|
14
|
+
it "initialize" do
|
15
|
+
Recurator.new({})
|
16
|
+
end
|
17
|
+
|
18
|
+
it "include Enumerable" do
|
19
|
+
Recurator.include?(Enumerable)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "each" do
|
23
|
+
ret = []
|
24
|
+
recur.each {|o|
|
25
|
+
ret << o
|
26
|
+
}
|
27
|
+
expect(ret).to eq([["one",{"two"=>{"three"=>3}}], ["two",{"three"=>3}], ["three",3]])
|
28
|
+
end
|
29
|
+
|
30
|
+
it "keys" do
|
31
|
+
expect(recur.keys).to eq(["one","two","three"])
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: recurator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ksss
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-03 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.11'
|
55
|
+
description: Recurator is object for recursive processing like Enumeator.
|
56
|
+
email:
|
57
|
+
- co000ri@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/recurator.bundle
|
67
|
+
- lib/recurator.rb
|
68
|
+
- lib/recurator/version.rb
|
69
|
+
- recurator.gemspec
|
70
|
+
- spec/helper.rb
|
71
|
+
- spec/recurator_spec.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.3
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Recurator is object for recursive processing like Enumeator.
|
96
|
+
test_files:
|
97
|
+
- spec/helper.rb
|
98
|
+
- spec/recurator_spec.rb
|