wilderpeople 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +21 -2
- data/lib/wilderpeople/search.rb +11 -7
- data/lib/wilderpeople/version.rb +15 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26c48edebe245cbafc5148e4cee8a83b7cd5bba4
|
4
|
+
data.tar.gz: 9839aeaf707ef84954a9388e6f7b92beb652c38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 415c1bf9ec3c123e1bc41370898418aa283e5a20b65867322da03b900a88d0bb851d3a15e2c9fad74912d98596ae9dbaf91c361fb536a5f70df96b6e18f0a514
|
7
|
+
data.tar.gz: 3888ea7c8becd071d831534af1419346b6db62aa1f91bb0b87b30f01a78d2175ef3279a6bd7cd4e3f36ba4fb736ab0a0ab265edbfbe35bb186802f59663fdbd4
|
data/.gitignore
CHANGED
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
|
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:
|
data/lib/wilderpeople/search.rb
CHANGED
@@ -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
|
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
|
45
|
-
# than any other, and if so return
|
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
|
-
|
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
|
data/lib/wilderpeople/version.rb
CHANGED
@@ -1,3 +1,17 @@
|
|
1
1
|
module Wilderpeople
|
2
|
-
VERSION = "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.
|
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-
|
11
|
+
date: 2017-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hypocorism
|