full_join 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/.circleci/config.yml +49 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +10 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/README.md +72 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/full_join.gemspec +32 -0
- data/lib/full_join.rb +8 -0
- data/lib/full_join/core_ext/array/full_join.rb +55 -0
- data/lib/full_join/version.rb +5 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3f565fec4fa7405fac0192c80d982c50095d07b4605f898eb21fa1ad69906a57
|
4
|
+
data.tar.gz: '028b129eee70e2bc219acd3c19e757d375e851cc5555b195f33b093f55b2b431'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aaf95f100da24e50085ddb9be3b015719d2a5718047bd98cc8118841d0569b94fe303904e06c72becd36a138fd6e6314ec0bc23aaa518fcbed6270d573da81e3
|
7
|
+
data.tar.gz: ed869b28fbb9ef9d4e731078a1c72a9fbe369e41230167d26b16e202029bb52ac62fba3162acaf02f0f0c72c2b7ca9f123e45221a2d7d75e4390ce5e4714c5e8
|
@@ -0,0 +1,49 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.6
|
6
|
+
working_directory: ~/repo
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- restore_cache:
|
10
|
+
keys:
|
11
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
12
|
+
- v1-dependencies-
|
13
|
+
- run:
|
14
|
+
name: configure bundler
|
15
|
+
command: |
|
16
|
+
echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
|
17
|
+
source $BASH_ENV
|
18
|
+
gem install bundler
|
19
|
+
- run:
|
20
|
+
name: install dependencies
|
21
|
+
command: |
|
22
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
23
|
+
- save_cache:
|
24
|
+
paths:
|
25
|
+
- ./vendor/bundle
|
26
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
27
|
+
- run:
|
28
|
+
name: run tests
|
29
|
+
command: |
|
30
|
+
mkdir /tmp/test-results
|
31
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
|
32
|
+
circleci tests split --split-by=timings)"
|
33
|
+
|
34
|
+
bundle exec rspec \
|
35
|
+
--format progress \
|
36
|
+
--format RspecJunitFormatter \
|
37
|
+
--out /tmp/test-results/rspec.xml \
|
38
|
+
--format progress \
|
39
|
+
$TEST_FILES
|
40
|
+
- store_test_results:
|
41
|
+
path: /tmp/test-results
|
42
|
+
- store_artifacts:
|
43
|
+
path: /tmp/test-results
|
44
|
+
destination: test-results
|
45
|
+
workflows:
|
46
|
+
version: 2
|
47
|
+
workflow:
|
48
|
+
jobs:
|
49
|
+
- build
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
full_join (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
jaro_winkler (1.5.3)
|
12
|
+
parallel (1.17.0)
|
13
|
+
parser (2.6.3.0)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.8.0)
|
18
|
+
rspec-core (~> 3.8.0)
|
19
|
+
rspec-expectations (~> 3.8.0)
|
20
|
+
rspec-mocks (~> 3.8.0)
|
21
|
+
rspec-core (3.8.2)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-expectations (3.8.4)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-mocks (3.8.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-support (3.8.2)
|
30
|
+
rubocop (0.73.0)
|
31
|
+
jaro_winkler (~> 1.5.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.6)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
37
|
+
ruby-progressbar (1.10.1)
|
38
|
+
unicode-display_width (1.6.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
bundler (~> 2.0)
|
45
|
+
full_join!
|
46
|
+
rake (~> 10.0)
|
47
|
+
rspec (~> 3.0)
|
48
|
+
rubocop
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.0.1
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# FullJoin
|
2
|
+
|
3
|
+
provides full join for Array
|
4
|
+
|
5
|
+
It looks like Array#zip, but detect same value and gather them like a Full Join.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'full_join'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install full_join
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Hoge = Struct.new(:id, keyword_init: true)
|
27
|
+
|
28
|
+
array1 = [Hoge.new(id: 1), Hoge.new(id: 2), Hoge.new(id: 3)]
|
29
|
+
array2 = [Hoge.new(id: 2), Hoge.new(id: 3), Hoge.new(id: 4)]
|
30
|
+
|
31
|
+
array1.full_join(array2) #=> [
|
32
|
+
[#<struct Hoge id=1>, nil]
|
33
|
+
[#<struct Hoge id=2>, #<struct Hoge id=2>]
|
34
|
+
[#<struct Hoge id=3>, #<struct Hoge id=3>]
|
35
|
+
[nil, #<struct Hoge id=4>]
|
36
|
+
]
|
37
|
+
```
|
38
|
+
|
39
|
+
also, like this
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
Hoge = Struct.new(:id, :name, keyword_init: true)
|
43
|
+
Fuga = Struct.new(:id, :name, keyword_init: true)
|
44
|
+
|
45
|
+
array1 = [
|
46
|
+
Hoge.new(id: 1, name: "AAA"),
|
47
|
+
Hoge.new(id: 2, name: "BBB"),
|
48
|
+
Hoge.new(id: 3, name: "CCC")
|
49
|
+
]
|
50
|
+
array2 = [
|
51
|
+
Fuga.new(id: 101, name: "BBB"),
|
52
|
+
Fuga.new(id: 102, name: "CCC"),
|
53
|
+
Fuga.new(id: 103, name: "DDD")
|
54
|
+
]
|
55
|
+
|
56
|
+
array1.full_join(array2, &:name) #=> [
|
57
|
+
[Hoge.new(id: 1, name: "AAA"), nil],
|
58
|
+
[Hoge.new(id: 2, name: "BBB"), Fuga.new(id: 101, name: "BBB")],
|
59
|
+
[Hoge.new(id: 3, name: "CCC"), Fuga.new(id: 102, name: "CCC")],
|
60
|
+
[nil, Fuga.new(id: 103, name: "DDD")]
|
61
|
+
]
|
62
|
+
```
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
|
+
|
68
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/naari3/full_join.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'full_join'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/full_join.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'full_join/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'full_join'
|
9
|
+
spec.version = FullJoin::VERSION
|
10
|
+
spec.authors = ['naari3']
|
11
|
+
spec.email = ['naari.named@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'provides full join for array'
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = 'https://github.com/naari3/full_join'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that
|
19
|
+
# have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'rspec_junit_formatter'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
32
|
+
end
|
data/lib/full_join.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# extension original class
|
4
|
+
class Array
|
5
|
+
# Returns a new array full joined other.
|
6
|
+
#
|
7
|
+
# @return [Array] a new array full joined other.
|
8
|
+
#
|
9
|
+
# @example
|
10
|
+
# Hoge = Struct.new(:id, keyword_init: true)
|
11
|
+
# array1 = [Hoge.new(id: 1), Hoge.new(id: 2), Hoge.new(id: 3)]
|
12
|
+
# array2 = [Hoge.new(id: 2), Hoge.new(id: 3), Hoge.new(id: 4)]
|
13
|
+
# array1.full_join(array2) #=> [
|
14
|
+
# [#<struct Hoge id=1>, nil]
|
15
|
+
# [#<struct Hoge id=2>, #<struct Hoge id=2>]
|
16
|
+
# [#<struct Hoge id=3>, #<struct Hoge id=3>]
|
17
|
+
# [nil, #<struct Hoge id=4>]
|
18
|
+
# ]
|
19
|
+
# @example
|
20
|
+
# Hoge = Struct.new(:id, :name, keyword_init: true)
|
21
|
+
# Fuga = Struct.new(:id, :name, keyword_init: true)
|
22
|
+
# array1 = [
|
23
|
+
# Hoge.new(id: 1, name: "AAA"),
|
24
|
+
# Hoge.new(id: 2, name: "BBB"),
|
25
|
+
# Hoge.new(id: 3, name: "CCC")
|
26
|
+
# ]
|
27
|
+
# array2 = [
|
28
|
+
# Fuga.new(id: 101, name: "BBB"),
|
29
|
+
# Fuga.new(id: 102, name: "CCC"),
|
30
|
+
# Fuga.new(id: 103, name: "DDD")
|
31
|
+
# ]
|
32
|
+
# array1.full_join(array2, &:name) #=> [
|
33
|
+
# [Hoge.new(id: 1, name: "AAA"), nil],
|
34
|
+
# [Hoge.new(id: 2, name: "BBB"), Fuga.new(id: 101, name: "BBB")],
|
35
|
+
# [Hoge.new(id: 3, name: "CCC"), Fuga.new(id: 102, name: "CCC")],
|
36
|
+
# [nil, Fuga.new(id: 103, name: "DDD")]
|
37
|
+
# ]
|
38
|
+
def full_join(other, &block)
|
39
|
+
block = ->(s) { s } unless block_given?
|
40
|
+
|
41
|
+
results = each_with_object([]) do |obj1, arr|
|
42
|
+
found = false
|
43
|
+
other.each do |obj2|
|
44
|
+
next unless block.call(obj1) == block.call(obj2)
|
45
|
+
|
46
|
+
arr << [obj1, obj2]
|
47
|
+
found = true
|
48
|
+
break
|
49
|
+
end
|
50
|
+
arr << [obj1, nil] unless found
|
51
|
+
end
|
52
|
+
|
53
|
+
results.concat((other - results.map(&:last)).zip([]).map(&:reverse))
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: full_join
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- naari3
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-18 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
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: provides full join for array
|
84
|
+
email:
|
85
|
+
- naari.named@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".circleci/config.yml"
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- bin/console
|
100
|
+
- bin/setup
|
101
|
+
- full_join.gemspec
|
102
|
+
- lib/full_join.rb
|
103
|
+
- lib/full_join/core_ext/array/full_join.rb
|
104
|
+
- lib/full_join/version.rb
|
105
|
+
homepage: https://github.com/naari3/full_join
|
106
|
+
licenses: []
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.7.3
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: provides full join for array
|
128
|
+
test_files: []
|