maxminddb 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/maxminddb/result.rb +2 -1
- data/lib/maxminddb/result/location.rb +1 -1
- data/lib/maxminddb/result/subdivisions.rb +17 -0
- data/lib/maxminddb/version.rb +1 -1
- data/spec/maxminddb/result/subdivisions_spec.rb +65 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2950442ee2ba4359f1b315e930bdd1b657d27b90
|
4
|
+
data.tar.gz: c0a2768251d072966bb978fd7590864ebc2d2e68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09488fd2b9863ea77ff054b500b218211187b2fa91e15307c7d126396a12b23be89c4932b92e92e6f5a57aca6e5a73da71c816e4d01c8632f65ca2d2634e0f85'
|
7
|
+
data.tar.gz: f8f60d819f9b81938a963cf0464462fcff067510db5ae6799b82531b60447d8812c7f3d353e4a7bcae596733faa5e9f9647af6c374d1b1558331b8aa40b2368e
|
data/CHANGELOG.md
CHANGED
data/lib/maxminddb/result.rb
CHANGED
@@ -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 ||=
|
50
|
+
@_subdivisions ||= Subdivisions.new(raw['subdivisions'])
|
50
51
|
end
|
51
52
|
|
52
53
|
def traits
|
@@ -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
|
data/lib/maxminddb/version.rb
CHANGED
@@ -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.
|
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-
|
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
|