ect 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE.txt +4 -1
  4. data/README.md +24 -2
  5. data/lib/ect.rb +6 -1
  6. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39640ca9b5241c26a75af47e0a1ecd2958921512
4
- data.tar.gz: 5010a8c7eea35df1e08308d7c919674002b10ae9
3
+ metadata.gz: 8fb9177137044779093c29ddca1d23ed822fabad
4
+ data.tar.gz: d33c980571b26a49b6564c8d1438585549cad468
5
5
  SHA512:
6
- metadata.gz: aff7be833138964e1964a41411035fc15b5ac1c425d07e38f8305d8e1813445832664f7c21dee05d5aeb097cb20c0699ec5f332500e3fb419695384dac694be8
7
- data.tar.gz: 59a427f2a7154d9337e28d5bd01ea3673ce6f5c529fa522f8c16f818b37111cd5a5884aad0015cd68119ff22011c31abc837236d89148500b406d4cd6a17b36f
6
+ metadata.gz: 49f3588de7f9c43a5ab7982b2655896355a85bb3f3901e2b928957df19d20ee37b51255baac75d0bd10c13e7c187a88c0e7cd40c68c53cf84ba3b93709c236bd
7
+ data.tar.gz: 63e283069d8008cdf7653da6c31802a6ac29f21fd7759433870352479efca88e0ca84c0047afc4dfb03e5fc71a0ff4f5a5fe22a76c0b4be31f729e5baaeded42
@@ -2,6 +2,11 @@
2
2
  # ect CHANGELOG.md
3
3
 
4
4
 
5
+ ## ect 1.1.0 released 2020-01-12
6
+
7
+ - Implement Enumerable#elect
8
+
9
+
5
10
  ## ect 1.0.0 released 2017-10-13
6
11
 
7
12
  - Alias #inflect to Object#tap
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2017-2017, John Mettraux, jmettraux@gmail.com
2
+ Copyright (c) 2017-2020, John Mettraux, jmettraux@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
@@ -19,3 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
19
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  THE SOFTWARE.
21
21
 
22
+
23
+ Made in Japan
24
+
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # ect
3
3
 
4
- [![Gem Version](https://badge.fury.io/rb/et-orbi.svg)](http://badge.fury.io/rb/ect)
4
+ [![Gem Version](https://badge.fury.io/rb/ect.svg)](http://badge.fury.io/rb/ect)
5
5
 
6
6
  Ruby methods ending in `ect`.
7
7
 
@@ -34,7 +34,7 @@ An alias to `#tap`. Passes the instance to the block, returns the instance.
34
34
  >
35
35
  > ORIGIN mid 16th cent.: from Latin deflectere, from de- ‘away from’ + flectere ‘to bend’.
36
36
 
37
- A very simple `yield(self)` (in Ruby 2.5.x it could thus become an alias to `#yiel_self`).
37
+ A very simple `yield(self)` (in Ruby 2.5.x it could thus become an alias to `#yield_self`).
38
38
 
39
39
  Passes the instance to the block, returns the result of the block. Change of direction.
40
40
 
@@ -44,6 +44,13 @@ Passes the instance to the block, returns the result of the block. Change of dir
44
44
  .collect(&:capitalize)
45
45
  ```
46
46
 
47
+ ```ruby
48
+ user = DB[:users]
49
+ .select(:id, :name)
50
+ .deflect { |x| id ? x.where(id: id) : x.where(name: name) }
51
+ .first
52
+ ```
53
+
47
54
  ## Enumerable
48
55
 
49
56
  ### Enumerable#bisect
@@ -92,6 +99,21 @@ p a1 # => nil
92
99
  p a2 # => [ 2, 5, 8, 11, 14 ]
93
100
  ```
94
101
 
102
+ ### Enumerable#elect
103
+
104
+ > elect |əˈlekt|
105
+ >
106
+ > ORIGIN late Middle English: from Latin elect- ‘picked out’, from the verb eligere, from e- (variant of ex-) ‘out’ + legere ‘to pick’.
107
+
108
+ Like a `find`, but yields the result of the block instead of the matching element.
109
+
110
+ ```ruby
111
+ a = [ { a: 1 }, { b: 2 }, { c: 3 } ]
112
+
113
+ a.elect { |e| e[:b] } # => 2
114
+ a.elect { |e| e[:z] } # => nil
115
+ ```
116
+
95
117
 
96
118
  ## LICENSE
97
119
 
data/lib/ect.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ect
3
3
 
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
6
6
 
7
7
 
@@ -24,5 +24,10 @@ module Enumerable
24
24
 
25
25
  inject([]) { |a, elt| (a[yield(elt)] ||= []) << elt; a }
26
26
  end
27
+
28
+ def elect
29
+
30
+ find { |elt| r = yield(elt); break r if r }
31
+ end
27
32
  end
28
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ect
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-13 00:00:00.000000000 Z
11
+ date: 2020-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  version: '0'
58
58
  requirements: []
59
59
  rubyforge_project:
60
- rubygems_version: 2.6.13
60
+ rubygems_version: 2.6.14.1
61
61
  signing_key:
62
62
  specification_version: 4
63
63
  summary: Methods ending in ect