chooser 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/Rakefile +5 -0
- data/chooser.gemspec +7 -1
- data/lib/chooser.rb +4 -0
- data/lib/chooser/version.rb +1 -1
- data/spec/chooser_spec.rb +52 -36
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eca9ca65c7b88da6221daf9f7a48b6025c9424b3
|
4
|
+
data.tar.gz: 97890457822593cad08a37ac4ec1a599e2262bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6508f0f735683775855e5a788b9ea9e6675c1f4de168e80cd8d1f0f6f9b16c11fa70352fb4bbc7fd65b6a48fccf6f16fef9921f05dab1632dc2101061f4f868b
|
7
|
+
data.tar.gz: 1c2cc59e851420d3459ce6b417fbf9f896940e68c52e26e6a3d18d5bb2b34e5db3a1ae809dee45756aa904f9d893f8c90a4a4fd1f3139513392305f9e00d4f3a
|
data/README.md
CHANGED
@@ -55,6 +55,12 @@ Filtering elements by instance evaluating string.
|
|
55
55
|
people.choose("age >= 29") # => [dave, nick, jack]
|
56
56
|
```
|
57
57
|
|
58
|
+
Rejecting elements with #choose_not method.
|
59
|
+
|
60
|
+
```rb
|
61
|
+
people.choose_not(:profession => "Programmer") # => [nick, jack]
|
62
|
+
```
|
63
|
+
|
58
64
|
## Contributing
|
59
65
|
|
60
66
|
1. Fork it ( http://github.com/<my-github-username>/chooser/fork )
|
data/Rakefile
CHANGED
data/chooser.gemspec
CHANGED
@@ -9,7 +9,13 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Alexander Avoyants"]
|
10
10
|
spec.email = ["shhavel@gmail.com"]
|
11
11
|
spec.summary = %q{Provides short interface for choosing elements from array of structs.}
|
12
|
-
spec.description = %q{Provides short interface for choosing elements from array of structs
|
12
|
+
spec.description = %q{Provides short interface for choosing elements from array of structs.
|
13
|
+
Filtering by equality, matching and inclusion, e.g.:
|
14
|
+
target.choose(:street => "Main", :age => (24..30), :address => /Main/)
|
15
|
+
Filtering by instance evaluated string, e.g.:
|
16
|
+
target.choose("age >= 24 && address =~ /^Main/")
|
17
|
+
Rejecting elements with #choose_not method, e.g.:
|
18
|
+
target.choose_not(:street => "Main")}
|
13
19
|
spec.homepage = ""
|
14
20
|
spec.license = "MIT"
|
15
21
|
|
data/lib/chooser.rb
CHANGED
data/lib/chooser/version.rb
CHANGED
data/spec/chooser_spec.rb
CHANGED
@@ -1,65 +1,81 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Chooser do
|
4
4
|
let(:alex) { Person.new("Alex", "Programmer", "123 Maple, Anytown NC", 27) }
|
5
5
|
let(:dave) { Person.new("Dave", "Programmer", "236 Main", 32) }
|
6
6
|
let(:nick) { Person.new("Nick", "Designer", "237 Main st.", 29) }
|
7
7
|
let(:jack) { Person.new("Jack", "QA", "1010 Center st.", 29) }
|
8
8
|
let(:people) { [alex, dave, nick, jack] }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
describe "Array#choose" do
|
11
|
+
context "choose elements by attribute equality" do
|
12
|
+
it "chooses elements with requested profession" do
|
13
|
+
expect(people.choose(:profession => "Programmer")).to match_array([alex, dave])
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
it "chooses elements with requested age" do
|
17
|
+
expect(people.choose(:age => 29)).to match_array([nick, jack])
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
it "chooses elements with requested profession and age" do
|
21
|
+
expect(people.choose(:profession => "Designer", :age => 29)).to match_array([nick])
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
it "returns empty array if no match found" do
|
25
|
+
expect(people.choose(:profession => "Designer", :age => 34)).to eq([])
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
context "choose elements by attribute inclusion" do
|
30
|
+
it "chooses elements with age included into requested array" do
|
31
|
+
expect(people.choose(:age => [29, 32])).to match_array([dave, nick, jack])
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
it "chooses elements with age included into requested array and with requested profession" do
|
35
|
+
expect(people.choose(:age => [29, 32], :profession => "QA")).to match_array([jack])
|
36
|
+
end
|
37
|
+
|
38
|
+
it "chooses elements with age included into requested range and with requested profession" do
|
39
|
+
expect(people.choose(:age => (27..29))).to match_array([alex, nick, jack])
|
40
|
+
end
|
41
|
+
|
42
|
+
it "chooses elements with age included into requested range and with matching profession" do
|
43
|
+
expect(people.choose(:age => (27..29), :profession => /Designer|QA/)).to match_array([nick, jack])
|
44
|
+
end
|
36
45
|
|
37
|
-
|
38
|
-
|
46
|
+
it "chooses elements with natched address" do
|
47
|
+
expect(people.choose(:address => /Main/)).to match_array([dave, nick])
|
48
|
+
end
|
39
49
|
end
|
40
50
|
|
41
|
-
|
42
|
-
|
51
|
+
context "choose elements by passing evaluated string of code" do
|
52
|
+
it "chooses elements with matched address" do
|
53
|
+
expect(people.choose("address =~ /Main/")).to match_array([dave, nick])
|
54
|
+
end
|
55
|
+
|
56
|
+
it "chooses elements with age less or euqual than requested" do
|
57
|
+
expect(people.choose("age <= 29")).to match_array([alex, nick, jack])
|
58
|
+
end
|
43
59
|
end
|
44
60
|
|
45
|
-
|
46
|
-
|
61
|
+
context "incorrect arguments" do
|
62
|
+
it "raises exception if receives incorrect argument" do
|
63
|
+
expect { people.choose([27, 29]) }.to raise_error ArgumentError
|
64
|
+
end
|
47
65
|
end
|
48
66
|
end
|
49
67
|
|
50
|
-
|
51
|
-
it "
|
52
|
-
expect(people.
|
68
|
+
describe "Array#choose_not" do
|
69
|
+
it "rejects elements choosed by attribute equality" do
|
70
|
+
expect(people.choose_not(:profession => "Programmer")).to match_array([nick, jack])
|
53
71
|
end
|
54
72
|
|
55
|
-
it "
|
56
|
-
expect(people.
|
73
|
+
it "rejects elements choosed with age included into requested array" do
|
74
|
+
expect(people.choose_not(:age => (27..29))).to match_array([dave])
|
57
75
|
end
|
58
|
-
end
|
59
76
|
|
60
|
-
|
61
|
-
|
62
|
-
expect { people.choose([27, 29]) }.to raise_error ArgumentError
|
77
|
+
it "rejects elements choosed with age less or euqual than requested and with profession equals requested" do
|
78
|
+
expect(people.choose_not("age <= 27 || profession == 'Designer'")).to match_array([dave, jack])
|
63
79
|
end
|
64
80
|
end
|
65
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chooser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Avoyants
|
@@ -52,9 +52,14 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
56
|
-
|
57
|
-
|
55
|
+
description: |-
|
56
|
+
Provides short interface for choosing elements from array of structs.
|
57
|
+
Filtering by equality, matching and inclusion, e.g.:
|
58
|
+
target.choose(:street => "Main", :age => (24..30), :address => /Main/)
|
59
|
+
Filtering by instance evaluated string, e.g.:
|
60
|
+
target.choose("age >= 24 && address =~ /^Main/")
|
61
|
+
Rejecting elements with #choose_not method, e.g.:
|
62
|
+
target.choose_not(:street => "Main")
|
58
63
|
email:
|
59
64
|
- shhavel@gmail.com
|
60
65
|
executables: []
|