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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53716cc454714a522fadd45257c84f270fed0506
4
- data.tar.gz: 9853fcd6204bfebb603c958d6e1940cec78a81f4
3
+ metadata.gz: eca9ca65c7b88da6221daf9f7a48b6025c9424b3
4
+ data.tar.gz: 97890457822593cad08a37ac4ec1a599e2262bff
5
5
  SHA512:
6
- metadata.gz: a29a7769381b61b14b2c6c01863f7396bf16197e64ff476839693be51ae4ef1a42bcd1c26e3383c8cd6069d362304d0b17e68db820ac9fa81647cedf78e208a0
7
- data.tar.gz: d4a7afda3ae9acaf206d570064e95021528fe43b3286b66f561393c2a56ca5eab7f4076785c866205afa0683a201f402b7d5d0a11f7abab68cc01461817885da
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
@@ -1,3 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+
2
3
  require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = ["-c", "-f documentation", "-r ./spec/spec_helper.rb"]
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
3
8
  task default: :spec
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, e.g. target.choose(:street => "Main", :age => (24..30), :address => /Main/) or target.choose("age >= 24 && address =~ /^Main/")}
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
@@ -20,6 +20,10 @@ module Chooser
20
20
  end
21
21
  ary
22
22
  end
23
+
24
+ def choose_not(selector)
25
+ self - choose(selector)
26
+ end
23
27
  end
24
28
 
25
29
  class Array
@@ -1,3 +1,3 @@
1
1
  module Chooser
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/chooser_spec.rb CHANGED
@@ -1,65 +1,81 @@
1
1
  require "spec_helper"
2
2
 
3
- describe "Array#choose" do
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
- context "choose elements by attribute equality" do
11
- it "chooses elements with requested profession" do
12
- expect(people.choose(:profession => "Programmer")).to match_array([alex, dave])
13
- end
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
- it "chooses elements with requested age" do
16
- expect(people.choose(:age => 29)).to match_array([nick, jack])
17
- end
16
+ it "chooses elements with requested age" do
17
+ expect(people.choose(:age => 29)).to match_array([nick, jack])
18
+ end
18
19
 
19
- it "chooses elements with requested profession and age" do
20
- expect(people.choose(:profession => "Designer", :age => 29)).to match_array([nick])
21
- end
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
- it "returns empty array if no match found" do
24
- expect(people.choose(:profession => "Designer", :age => 34)).to eq([])
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
- context "choose elements by attribute inclusion" do
29
- it "chooses elements with age included into requested array" do
30
- expect(people.choose(:age => [29, 32])).to match_array([dave, nick, jack])
31
- end
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
- it "chooses elements with age included into requested array and with requested profession" do
34
- expect(people.choose(:age => [29, 32], :profession => "QA")).to match_array([jack])
35
- end
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
- it "chooses elements with age included into requested range and with requested profession" do
38
- expect(people.choose(:age => (27..29))).to match_array([alex, nick, jack])
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
- it "chooses elements with age included into requested range and with matching profession" do
42
- expect(people.choose(:age => (27..29), :profession => /Designer|QA/)).to match_array([nick, jack])
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
- it "chooses elements with natched address" do
46
- expect(people.choose(:address => /Main/)).to match_array([dave, nick])
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
- context "choose elements by passing evaluated string of code" do
51
- it "chooses elements with matched address" do
52
- expect(people.choose("address =~ /Main/")).to match_array([dave, nick])
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 "chooses elements with age less or euqual than requested" do
56
- expect(people.choose("age <= 29")).to match_array([alex, nick, jack])
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
- context "incorrect arguments" do
61
- it "raises exception if receives incorrect argument" do
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.2
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: Provides short interface for choosing elements from array of structs,
56
- e.g. target.choose(:street => "Main", :age => (24..30), :address => /Main/) or target.choose("age
57
- >= 24 && address =~ /^Main/")
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: []