maxminddb 0.1.14 → 0.1.15

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: 19d1e58b79d3beb9ed5bd74ffdf5da41d62f5be4
4
- data.tar.gz: d8e3f6acbc575111367caf90d73c0d3549061084
3
+ metadata.gz: 2950442ee2ba4359f1b315e930bdd1b657d27b90
4
+ data.tar.gz: c0a2768251d072966bb978fd7590864ebc2d2e68
5
5
  SHA512:
6
- metadata.gz: 46d7fa5b3bd159eeae83360bff4dfe86ebfdbb1da2de64690d0a47a019437f6aee2464af7b6d4a88a11f79ed1253d1b3a0038ea9a4102ca242d31b5e3682f5fb
7
- data.tar.gz: '028ee475caa88471dcd6bdbf35e7e66b75c6ae179e209d030d90c788c02413f41cf9900e89b4252500e070270e4a9531b8a945cfb7f80a25c27ee28c3f363cc9'
6
+ metadata.gz: '09488fd2b9863ea77ff054b500b218211187b2fa91e15307c7d126396a12b23be89c4932b92e92e6f5a57aca6e5a73da71c816e4d01c8632f65ca2d2634e0f85'
7
+ data.tar.gz: f8f60d819f9b81938a963cf0464462fcff067510db5ae6799b82531b60447d8812c7f3d353e4a7bcae596733faa5e9f9647af6c374d1b1558331b8aa40b2368e
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.1.15 (December 18, 2017)
4
+
5
+ - Implement #most_specific method for result subdivisions #31
6
+
3
7
  ### 0.1.14 (July 26, 2017)
4
8
 
5
9
  - Expose accuracy_radius in Location data #29
@@ -1,6 +1,7 @@
1
1
  require_relative 'result/location'
2
2
  require_relative 'result/named_location'
3
3
  require_relative 'result/postal'
4
+ require_relative 'result/subdivisions'
4
5
  require_relative 'result/traits'
5
6
 
6
7
  module MaxMindDB
@@ -46,7 +47,7 @@ module MaxMindDB
46
47
  end
47
48
 
48
49
  def subdivisions
49
- @_subdivisions ||= Array(raw['subdivisions']).map { |hash| NamedLocation.new(hash) }
50
+ @_subdivisions ||= Subdivisions.new(raw['subdivisions'])
50
51
  end
51
52
 
52
53
  def traits
@@ -20,7 +20,7 @@ module MaxMindDB
20
20
  def time_zone
21
21
  raw['time_zone']
22
22
  end
23
-
23
+
24
24
  def accuracy_radius
25
25
  raw['accuracy_radius']
26
26
  end
@@ -0,0 +1,17 @@
1
+ module MaxMindDB
2
+ class Result
3
+ class Subdivisions < Array
4
+ def initialize(raw)
5
+ super((raw || []).map { |hash| NamedLocation.new(hash) })
6
+ end
7
+
8
+ def most_specific
9
+ last || NamedLocation.new({})
10
+ end
11
+
12
+ def inspect
13
+ "#<MaxMindDB::Result::Subdivisions: #{super}>"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module MaxMindDB
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
@@ -0,0 +1,65 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'maxminddb'
3
+
4
+ describe MaxMindDB::Result::Subdivisions do
5
+ subject(:subdivisions) { described_class.new(raw_subdivisions) }
6
+
7
+ context "with multiple subdivisions" do
8
+ let(:raw_subdivisions) { [{
9
+ "geoname_id"=>5037779,
10
+ "iso_code"=>"MN",
11
+ "names"=>{"en"=>"Minnesota"}
12
+ }, {
13
+ "geoname_id"=>123,
14
+ "iso_code"=>"HP",
15
+ "names"=>{"en"=>"Hennepin"}
16
+ }] }
17
+
18
+ it 'should be a kind of Array' do
19
+ expect(subdivisions).to be_kind_of(Array)
20
+ end
21
+
22
+ it 'should return as many items as there are subdivisions passed in' do
23
+ expect(subdivisions.length).to eq(raw_subdivisions.length)
24
+ end
25
+
26
+ it 'should contain only MaxMindDB::Result::NamedLocation' do
27
+ expect(subdivisions.all? { |r| r.kind_of?(MaxMindDB::Result::NamedLocation)}).to be_truthy
28
+ end
29
+
30
+ describe "most_specific" do
31
+ it 'should be a kind of MaxMindDB::Result::NamedLocation' do
32
+ expect(subdivisions.most_specific).to be_kind_of(MaxMindDB::Result::NamedLocation)
33
+ end
34
+
35
+ it 'should eq "Hennepin" subdivision' do
36
+ expect(subdivisions.most_specific.name).to eq("Hennepin")
37
+ end
38
+ end
39
+ end
40
+
41
+ context "without a result" do
42
+ let(:raw_subdivisions) { nil }
43
+
44
+ it 'should be a kind of Array' do
45
+ expect(subdivisions).to be_kind_of(Array)
46
+ end
47
+
48
+ it 'should be empty' do
49
+ expect(subdivisions.length).to eq(0)
50
+ end
51
+
52
+ describe "most_specific" do
53
+ it 'should be a kind of MaxMindDB::Result::NamedLocation' do
54
+ expect(subdivisions.most_specific).to be_kind_of(MaxMindDB::Result::NamedLocation)
55
+ end
56
+
57
+ it 'should be an empty MaxMindDB::Result::NamedLocation' do
58
+ expect(subdivisions.most_specific.code).to eq(nil)
59
+ expect(subdivisions.most_specific.geoname_id).to eq(nil)
60
+ expect(subdivisions.most_specific.iso_code).to eq(nil)
61
+ expect(subdivisions.most_specific.name).to eq(nil)
62
+ end
63
+ end
64
+ end
65
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxminddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - yhirose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-26 00:00:00.000000000 Z
11
+ date: 2017-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,7 @@ files:
86
86
  - lib/maxminddb/result/location.rb
87
87
  - lib/maxminddb/result/named_location.rb
88
88
  - lib/maxminddb/result/postal.rb
89
+ - lib/maxminddb/result/subdivisions.rb
89
90
  - lib/maxminddb/result/traits.rb
90
91
  - lib/maxminddb/version.rb
91
92
  - maxminddb.gemspec
@@ -94,6 +95,7 @@ files:
94
95
  - spec/maxminddb/result/location_spec.rb
95
96
  - spec/maxminddb/result/named_location_spec.rb
96
97
  - spec/maxminddb/result/postal_spec.rb
98
+ - spec/maxminddb/result/subdivisions_spec.rb
97
99
  - spec/maxminddb/result/trait_spec.rb
98
100
  - spec/maxminddb/result_spec.rb
99
101
  - spec/maxminddb_spec.rb
@@ -127,6 +129,7 @@ test_files:
127
129
  - spec/maxminddb/result/location_spec.rb
128
130
  - spec/maxminddb/result/named_location_spec.rb
129
131
  - spec/maxminddb/result/postal_spec.rb
132
+ - spec/maxminddb/result/subdivisions_spec.rb
130
133
  - spec/maxminddb/result/trait_spec.rb
131
134
  - spec/maxminddb/result_spec.rb
132
135
  - spec/maxminddb_spec.rb