wilderpeople 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4591ba4d3f4654cae88164e3106ef022b0dfbc32
4
- data.tar.gz: d364ee06d64951745386aba6b7fadbc3783cd4e5
3
+ metadata.gz: 26c48edebe245cbafc5148e4cee8a83b7cd5bba4
4
+ data.tar.gz: 9839aeaf707ef84954a9388e6f7b92beb652c38f
5
5
  SHA512:
6
- metadata.gz: 756050f37ba7b4ed278e80276b977d006ed74fd7ef8cfc1c29819ffed3c5c9623d1b03b085d9b53711872508365c2d547aad1379b86532485556df6eb18a2fc9
7
- data.tar.gz: 4068c8206a34f4f0bac26d7eb7f7c34663ed090a8cd2f18510aefc15965ae54425c252c9053a84644b5acd228cee282187f5a3e59d072776cd25e1a0fc8549d9
6
+ metadata.gz: 415c1bf9ec3c123e1bc41370898418aa283e5a20b65867322da03b900a88d0bb851d3a15e2c9fad74912d98596ae9dbaf91c361fb536a5f70df96b6e18f0a514
7
+ data.tar.gz: 3888ea7c8becd071d831534af1419346b6db62aa1f91bb0b87b30f01a78d2175ef3279a6bd7cd4e3f36ba4fb736ab0a0ab265edbfbe35bb186802f59663fdbd4
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/README.md CHANGED
@@ -6,8 +6,7 @@ other types of data from an array.
6
6
 
7
7
  The tool assumes you have an array of hashes, where each hash describes an
8
8
  unique item or person. It then allows you to pass in a "matching dataset" and
9
- in return it will return the hash that best matches that data, **if there
10
- is only one best match.**
9
+ in return it will return the hash that best matches that data.
11
10
 
12
11
  ## Installation
13
12
 
@@ -98,6 +97,26 @@ person = search.find surname: 'Bloggs', forename: 'Fred', gender: 'Female'
98
97
  person == {surname: 'Bloggs', forename: 'Winifred', gender: 'Female'}
99
98
  ```
100
99
 
100
+ ### Select
101
+
102
+ If it is not necessary to return a unique record, `select` can be used to
103
+ retrieve all the items that match the `config` criteria.
104
+
105
+ ```ruby
106
+ config = {
107
+ must: {
108
+ surname: :exact,
109
+ gender: :exact
110
+ }
111
+ }
112
+ search = Wilderpeople::Search.new(data: data, config: config)
113
+ person = search.select surname: 'Bloggs', gender: 'Female'
114
+ person == [
115
+ {"surname"=>"Bloggs", "forename"=>"Winifred", "gender"=>"Female"},
116
+ {"surname"=>"Bloggs", "forename"=>"Jane", "gender"=>"Female"}
117
+ ]
118
+ ```
119
+
101
120
  ### Criteria configuration
102
121
 
103
122
  The `config` is a hash of one or two parts. The parts being:
@@ -8,9 +8,16 @@ module Wilderpeople
8
8
  end
9
9
 
10
10
  def find(args)
11
+ select(args)
12
+ result.first if result.size == 1
13
+ end
14
+
15
+ def select(args)
11
16
  @result = data
12
17
  @args = args
13
- select_must || select_can
18
+ select_must
19
+ select_can if result.size > 1
20
+ result
14
21
  end
15
22
 
16
23
  private
@@ -24,7 +31,6 @@ module Wilderpeople
24
31
  Matcher.by matcher_method, datum[key], args[key]
25
32
  end
26
33
  end
27
- result.first if result.size == 1
28
34
  end
29
35
 
30
36
  def must_rules
@@ -41,13 +47,11 @@ module Wilderpeople
41
47
  Matcher.by matcher_method, datum[key], args[key]
42
48
  end
43
49
  end
44
- # Then determine if one datum appears in more matches
45
- # than any other, and if so return that one.
50
+ # Then determine which items appears in more matches
51
+ # than any other, and if so return those.
46
52
  occurrences = find_occurrences(matches)
47
53
  count_of_commonest = occurrences.values.max
48
- if occurrences.values.count(count_of_commonest) == 1
49
- occurrences.rassoc(count_of_commonest)[0]
50
- end
54
+ @result = occurrences.select{|_k, v| v == count_of_commonest}.keys
51
55
  end
52
56
 
53
57
  def can_rules
@@ -1,3 +1,17 @@
1
1
  module Wilderpeople
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
4
+
5
+ # History
6
+ # =======
7
+ #
8
+ # 0.1.0: Initial release
9
+ # ----------------------
10
+ # Basic functionality working that allows unique items to be retrieved from
11
+ # a data set based on a set of criteria and a matching dataset.
12
+ #
13
+ # 0.2.0: Add select to return matching items
14
+ # ------------------------------------------
15
+ # Added a `select` method to search, that will return all the matching items
16
+ #
17
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wilderpeople
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Nichols
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-09 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hypocorism