widgeo 0.0.2 → 0.0.3
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +10 -2
- data/lib/widgeo/collection.rb +18 -0
- data/lib/widgeo/version.rb +1 -1
- data/spec/widgeo/territory_spec.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e846be8a47e0a351ffd5d668240e57946c83177d
|
4
|
+
data.tar.gz: 618ac392fcae389f28b00fe87008071dda72ef08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26d6769ed5a683efb39901c9ff84f2194b8f65054c04c6cdb79d646ed65a283774523979ce2404273bdab14726954873b61544549b03cf074302acdc8cf82ea
|
7
|
+
data.tar.gz: c28b788e703b6f43c9e1a0df117c8f2dfcdf0b20793154cd35bd2152d67d1064f6f58f73c26f4d695b09fe6248e06d2266db369ac74c37951f422f4e9bacdf77
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Widgeo provides easy access to the worlds territories and their continents.
|
|
6
6
|
|
7
7
|
Include Widgeo in your Gemfile, `gem "widgeo", require: true` and run `bundle install`.
|
8
8
|
|
9
|
-
####
|
9
|
+
#### .all
|
10
10
|
|
11
11
|
Provides a list of all items.
|
12
12
|
|
@@ -18,7 +18,15 @@ and all territories:
|
|
18
18
|
|
19
19
|
`territories = Widgeo::Territory.all`
|
20
20
|
|
21
|
-
####
|
21
|
+
#### .filter_by
|
22
|
+
|
23
|
+
Allows for filtering a list of items.
|
24
|
+
|
25
|
+
For a filtered list of territories in the EU:
|
26
|
+
|
27
|
+
`territories = Widgeo::Territories.filter_by continent_alpha_2: "EU"`
|
28
|
+
|
29
|
+
#### .find_by
|
22
30
|
|
23
31
|
Provides a single item matching a specified property and value.
|
24
32
|
|
data/lib/widgeo/collection.rb
CHANGED
@@ -21,6 +21,24 @@ module Widgeo
|
|
21
21
|
|
22
22
|
end
|
23
23
|
|
24
|
+
# Does the item match the requested attributes?
|
25
|
+
def matches? item, attributes
|
26
|
+
|
27
|
+
attributes.map { |attribute, value|
|
28
|
+
|
29
|
+
item.send(attribute) == value
|
30
|
+
|
31
|
+
}.flatten == [true]
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
# Filter the items by a combination of values
|
36
|
+
def filter_by attributes
|
37
|
+
|
38
|
+
all.select { |item| matches? item, attributes }
|
39
|
+
|
40
|
+
end
|
41
|
+
|
24
42
|
# Find an item by an attribute
|
25
43
|
def find_by attribute, value
|
26
44
|
|
data/lib/widgeo/version.rb
CHANGED
@@ -5,6 +5,7 @@ describe Widgeo::Territory do
|
|
5
5
|
TERRITORY_COUNT = 254
|
6
6
|
INVALID_TERRITORY = { bad_field: "BAD FIELD" }
|
7
7
|
TERRITORY_ALPHA = "GB"
|
8
|
+
EU_TERRITORY_COUNT = 50
|
8
9
|
PARENT_CONTINENT_ALPHA = "EU"
|
9
10
|
|
10
11
|
VALID_TERRITORY = {
|
@@ -46,6 +47,18 @@ describe Widgeo::Territory do
|
|
46
47
|
|
47
48
|
end
|
48
49
|
|
50
|
+
describe ".filter_by" do
|
51
|
+
|
52
|
+
subject(:territories) {
|
53
|
+
Widgeo::Territory.filter_by continent_alpha_2: PARENT_CONTINENT_ALPHA
|
54
|
+
}
|
55
|
+
|
56
|
+
it { expect(territories).to be_kind_of Array }
|
57
|
+
it { expect(territories.size).to be EU_TERRITORY_COUNT }
|
58
|
+
it { expect(territories.first).to be_kind_of Widgeo::Territory }
|
59
|
+
|
60
|
+
end
|
61
|
+
|
49
62
|
describe ".all" do
|
50
63
|
|
51
64
|
subject(:territories) { Widgeo::Territory.all }
|