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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2aa0a07dfb5675efc75c797d1e22e17a458af98
4
- data.tar.gz: 61928468ade60db782e26dafc8a25166aabd27e2
3
+ metadata.gz: e846be8a47e0a351ffd5d668240e57946c83177d
4
+ data.tar.gz: 618ac392fcae389f28b00fe87008071dda72ef08
5
5
  SHA512:
6
- metadata.gz: 91f8f6728d144742ae282532f2ea8388bc383b0f26f719e108494b5039aaa0150649e7f6e27ab27a66e8fec96dbd9f9542499d317899b508d2d00823d7f1f5b4
7
- data.tar.gz: 6a4988c7d7b2d54e6768bbd1a2a613ef949a86e86b2d66d683ff07b276eb01280ba95238901ed8e911bb8052eacbe7afb47353c336e9437c9f9ef88ea45900f0
6
+ metadata.gz: f26d6769ed5a683efb39901c9ff84f2194b8f65054c04c6cdb79d646ed65a283774523979ce2404273bdab14726954873b61544549b03cf074302acdc8cf82ea
7
+ data.tar.gz: c28b788e703b6f43c9e1a0df117c8f2dfcdf0b20793154cd35bd2152d67d1064f6f58f73c26f4d695b09fe6248e06d2266db369ac74c37951f422f4e9bacdf77
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
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
- #### #all
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
- #### #find_by
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
 
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Widgeo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: widgeo
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
  - Chris G