enrichment_db 0.0.2 → 0.1.0
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/.DS_Store +0 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +58 -0
- data/LICENSE +20 -0
- data/Rakefile +11 -0
- data/enrichment_db.gemspec +31 -0
- data/lib/enrichment_db.rb +38 -0
- data/lib/enrichment_db/.DS_Store +0 -0
- data/lib/enrichment_db/db.rb +40 -0
- data/lib/enrichment_db/error.rb +7 -0
- data/lib/enrichment_db/geo.rb +14 -0
- data/lib/enrichment_db/geo/locator.rb +102 -0
- data/lib/enrichment_db/geo/postcode.rb +16 -0
- data/lib/enrichment_db/geo/region.rb +52 -0
- data/lib/enrichment_db/geo/sa1.rb +16 -0
- data/lib/enrichment_db/geo/sa2.rb +16 -0
- data/lib/enrichment_db/geo/sa3.rb +16 -0
- data/lib/enrichment_db/geo/sa4.rb +16 -0
- data/lib/enrichment_db/geo/state.rb +13 -0
- data/lib/enrichment_db/geo/suburb.rb +13 -0
- data/lib/enrichment_db/version.rb +3 -0
- data/test/.DS_Store +0 -0
- data/test/factories/postcode.rb +7 -0
- data/test/factories/sa1.rb +7 -0
- data/test/factories/sa2.rb +8 -0
- data/test/factories/sa3.rb +8 -0
- data/test/factories/sa4.rb +8 -0
- data/test/factories/state.rb +8 -0
- data/test/factories/suburb.rb +8 -0
- data/test/geo/locator_test.rb +41 -0
- data/test/reports/TEST-EnrichmentDb-Geo-Locator.xml +11 -0
- data/test/test_helper.rb +23 -0
- metadata +66 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f741a0f881ad8ee9b09cd3a4efc4c92b98fcbeeb
|
4
|
+
data.tar.gz: 06ec8db95c457f3a0b763c4b672d7a16cc8d9f19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee73180341e7549eaa97191a8eaaf5250498cec035de6b258845c5c137f6f23814ddd954158b78fa50a360a0e3296c79328ba1e490ae8c2966cb069d1e28eaff
|
7
|
+
data.tar.gz: 796c37fdd9cae746ad9d662448c880a204ec3e4ed4f633a9f95a5f192097fbf717eede39d2fa2e033a4a21275fa0f1ef23a90d56d65dbd90cb44c9a9601db26c
|
data/.DS_Store
ADDED
Binary file
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
enrichment_db (0.0.1)
|
5
|
+
multi_json (~> 1.3)
|
6
|
+
pg
|
7
|
+
pr_geohash
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (4.2.3)
|
13
|
+
i18n (~> 0.7)
|
14
|
+
json (~> 1.7, >= 1.7.7)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
addressable (2.3.8)
|
19
|
+
ansi (1.5.0)
|
20
|
+
builder (3.2.2)
|
21
|
+
crack (0.4.2)
|
22
|
+
safe_yaml (~> 1.0.0)
|
23
|
+
factory_girl (4.5.0)
|
24
|
+
activesupport (>= 3.0.0)
|
25
|
+
faker (1.5.0)
|
26
|
+
i18n (~> 0.5)
|
27
|
+
i18n (0.7.0)
|
28
|
+
json (1.8.3)
|
29
|
+
minitest (5.7.0)
|
30
|
+
minitest-reporters (1.0.17)
|
31
|
+
ansi
|
32
|
+
builder
|
33
|
+
minitest (>= 5.0)
|
34
|
+
ruby-progressbar
|
35
|
+
multi_json (1.11.2)
|
36
|
+
pg (0.18.2)
|
37
|
+
pr_geohash (1.0.0)
|
38
|
+
rake (10.4.2)
|
39
|
+
ruby-progressbar (1.7.5)
|
40
|
+
safe_yaml (1.0.4)
|
41
|
+
thread_safe (0.3.5)
|
42
|
+
tzinfo (1.2.2)
|
43
|
+
thread_safe (~> 0.1)
|
44
|
+
webmock (1.21.0)
|
45
|
+
addressable (>= 2.3.6)
|
46
|
+
crack (>= 0.3.2)
|
47
|
+
|
48
|
+
PLATFORMS
|
49
|
+
ruby
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
enrichment_db!
|
53
|
+
factory_girl
|
54
|
+
faker
|
55
|
+
minitest
|
56
|
+
minitest-reporters
|
57
|
+
rake
|
58
|
+
webmock
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Lexer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'enrichment_db/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'enrichment_db'
|
7
|
+
s.version = EnrichmentDb::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.licenses = ['MIT']
|
10
|
+
s.authors = ['Aaron Wallis']
|
11
|
+
s.email = 'code@Lexer.io'
|
12
|
+
s.homepage = 'https://github.com/lexerdev/enrichment-db.gem'
|
13
|
+
s.summary = 'Lexer Enrichment Database Gem'
|
14
|
+
s.description = 'Consume static data from the Lexer Enrichment database.'
|
15
|
+
|
16
|
+
s.add_dependency 'multi_json', '~> 1.3'
|
17
|
+
s.add_dependency 'pg'
|
18
|
+
s.add_dependency 'pr_geohash'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split($RS).reject do |file|
|
21
|
+
file =~ %r{^(?:
|
22
|
+
spec/.*
|
23
|
+
|Gemfile
|
24
|
+
|Rakefile
|
25
|
+
|\.gitignore
|
26
|
+
|\.rubocop.yml
|
27
|
+
)$}x
|
28
|
+
end
|
29
|
+
s.test_files = `git ls-files`.split($RS)
|
30
|
+
s.require_paths = ['lib']
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'enrichment_db/error'
|
2
|
+
require 'enrichment_db/version'
|
3
|
+
|
4
|
+
module EnrichmentDb
|
5
|
+
module_function
|
6
|
+
|
7
|
+
class DatumModel
|
8
|
+
attr_accessor :attrs
|
9
|
+
alias :to_hash :attrs
|
10
|
+
|
11
|
+
# Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
|
12
|
+
#
|
13
|
+
# @overload self.lazy_attr_reader(attr)
|
14
|
+
# @param attr [Symbol]
|
15
|
+
# @overload self.lazy_attr_reader(attrs)
|
16
|
+
# @param attrs [Array<Symbol>]
|
17
|
+
def self.lazy_attr_reader(*attrs)
|
18
|
+
attrs.each do |attribute|
|
19
|
+
class_eval do
|
20
|
+
define_method attribute do
|
21
|
+
@attrs[attribute.to_s] || @attrs[attribute.to_sym]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Initializes a new Base object
|
28
|
+
#
|
29
|
+
# @param attrs [Hash]
|
30
|
+
# @return [DatumModel]
|
31
|
+
def initialize(attrs={})
|
32
|
+
@attrs = attrs.dup
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
require 'enrichment_db/geo'
|
38
|
+
require 'db'
|
Binary file
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'pg'
|
2
|
+
|
3
|
+
module EnrichmentDb
|
4
|
+
def self.db_connection
|
5
|
+
@__db_connection ||= PGconn.connect(
|
6
|
+
host:'geo-mappings.cfmmyp7uix0j.ap-southeast-2.rds.amazonaws.com',
|
7
|
+
dbname:'geo',
|
8
|
+
user: 'lexer',
|
9
|
+
password: 'campl3x3r'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.reset_connection
|
14
|
+
@__api_connection = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.request(query, values)
|
18
|
+
type = request_type(query)
|
19
|
+
|
20
|
+
case type
|
21
|
+
when :select, 'select'
|
22
|
+
result = if values
|
23
|
+
EnrichmentDb::db_connection.exec(query, values)
|
24
|
+
else
|
25
|
+
EnrichmentDb::db_connection.exec(query)
|
26
|
+
end
|
27
|
+
when :insert, :drop, :delete, 'insert', 'drop', 'delete'
|
28
|
+
fail EnrichmentDb::RequestError, "Postgres method '#{type}' is unsupported"
|
29
|
+
else
|
30
|
+
fail EnrichmentDb::RequestError, "Postgres query '#{query}' is unsupported"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.request_type(query)
|
35
|
+
result = query.downcase.match(/(^(?:drop|select|insert|delete))/)
|
36
|
+
return unless result
|
37
|
+
|
38
|
+
result[0]
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
|
3
|
+
module EnrichmentDb::Geo
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'geo/region'
|
7
|
+
require 'geo/locator'
|
8
|
+
require 'geo/postcode'
|
9
|
+
require 'geo/sa1'
|
10
|
+
require 'geo/sa2'
|
11
|
+
require 'geo/sa3'
|
12
|
+
require 'geo/sa4'
|
13
|
+
require 'geo/state'
|
14
|
+
require 'geo/suburb'
|
@@ -0,0 +1,102 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
|
3
|
+
require 'geo/postcode'
|
4
|
+
require 'geo/sa1'
|
5
|
+
require 'geo/sa2'
|
6
|
+
require 'geo/sa3'
|
7
|
+
require 'geo/sa4'
|
8
|
+
require 'geo/state'
|
9
|
+
require 'geo/suburb'
|
10
|
+
|
11
|
+
require 'pr_geohash'
|
12
|
+
|
13
|
+
class EnrichmentDb::Geo::Locator < EnrichmentDb::DatumModel
|
14
|
+
attr_reader :id
|
15
|
+
attr_reader :name
|
16
|
+
attr_reader :state
|
17
|
+
attr_reader :sa4
|
18
|
+
attr_reader :sa3
|
19
|
+
attr_reader :sa2
|
20
|
+
attr_reader :sa1
|
21
|
+
attr_reader :postcode
|
22
|
+
attr_reader :suburb
|
23
|
+
attr_reader :smallest_region
|
24
|
+
|
25
|
+
def initialize(data)
|
26
|
+
self.class.all_regions.each do |region|
|
27
|
+
region_name = region.object_type
|
28
|
+
region_data = data[region_name]
|
29
|
+
region_instance = !!region_data ? region.new(region_data) : nil
|
30
|
+
instance_variable_set("@#{region_name}", region_instance)
|
31
|
+
|
32
|
+
if data['smallest_region'] == region_name
|
33
|
+
@id = region_data['id']
|
34
|
+
@name = region_data['name']
|
35
|
+
@smallest_region = region_name
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.geo_locate(geohash)
|
41
|
+
geohash = format_geo(geohash)
|
42
|
+
values = [geohash]
|
43
|
+
|
44
|
+
data = {}
|
45
|
+
all_regions.each do |region|
|
46
|
+
region_name = region.object_type
|
47
|
+
region_id = find_id(data, region_name)
|
48
|
+
|
49
|
+
result = if !region_id.nil?
|
50
|
+
region.by_id(region_id)
|
51
|
+
else
|
52
|
+
region.by_boundary(values)
|
53
|
+
end
|
54
|
+
data['smallest_region'] ||= region_name if !result.nil?
|
55
|
+
data[region_name] = result
|
56
|
+
end
|
57
|
+
self.new(data)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.find_id(data, region_type)
|
61
|
+
id = "#{region_type}_id"
|
62
|
+
data.each do |k, v|
|
63
|
+
return v[id] if v.is_a?(Hash) && v.keys.include?(id)
|
64
|
+
end
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.all_regions
|
69
|
+
all_region_names.collect do |region|
|
70
|
+
EnrichmentDb::Geo.const_get(region)
|
71
|
+
end.sort_by do |region|
|
72
|
+
region.scale
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.all_region_names
|
77
|
+
EnrichmentDb::Geo.constants - [:Region, :Locator]
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.format_geo(geo)
|
81
|
+
return geo if geo.is_a?(String)
|
82
|
+
|
83
|
+
fail EnrichmentDb::InvalidFormat unless valid_geo_point?(geo)
|
84
|
+
geo[:lat] ||= geo['lat']
|
85
|
+
geo[:long] ||= geo['long']
|
86
|
+
GeoHash.encode(geo[:lat], geo[:long])
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.valid_geo_point?(geo_point)
|
90
|
+
geo_point.is_a?(Hash) && geo_point.keys.sort.collect(&:to_sym) == [:lat, :long]
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def self.object_type
|
96
|
+
to_s.split(':').last.downcase.to_sym
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.make_table_name(object_name)
|
100
|
+
"#{object_name}s"
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
require 'sa3'
|
3
|
+
|
4
|
+
class EnrichmentDb::Geo::Postcode < EnrichmentDb::Geo::Region
|
5
|
+
def self.fields
|
6
|
+
'id, sa3_id, sa4_id, state_id'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.scale
|
10
|
+
13
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parent_class
|
14
|
+
EnrichmentDb::Geo::SA3
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class EnrichmentDb::Geo::Region < EnrichmentDb::DatumModel
|
2
|
+
attr_reader :id
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(data)
|
6
|
+
@id = data['id']
|
7
|
+
@name = data['name']
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.by_id(id)
|
11
|
+
puts "Finding #{object_type} with id = '#{id}'."
|
12
|
+
field_names = fields
|
13
|
+
table = make_table_name
|
14
|
+
query = "SELECT #{field_names} FROM #{table} where id = $1"
|
15
|
+
values = [id]
|
16
|
+
|
17
|
+
result = EnrichmentDb.request(query, values)
|
18
|
+
if result.ntuples == 1
|
19
|
+
puts "Found #{object_type}"
|
20
|
+
result[0]
|
21
|
+
else
|
22
|
+
puts "Nothing found"
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.by_boundary(values)
|
28
|
+
puts "Finding #{object_type} intersecting with some geohash"
|
29
|
+
field_names = fields
|
30
|
+
table = make_table_name
|
31
|
+
query = "SELECT #{field_names} FROM #{table} where ST_Within(ST_SetSRID(ST_GeomFromGeoHash($1), 4283), boundary)"
|
32
|
+
|
33
|
+
result = EnrichmentDb.request(query, values)
|
34
|
+
if result.ntuples == 1
|
35
|
+
puts "Found #{object_type}"
|
36
|
+
result[0]
|
37
|
+
else
|
38
|
+
puts "Nothing found"
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def self.object_type
|
46
|
+
to_s.split(':').last.downcase.to_sym
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.make_table_name
|
50
|
+
"#{object_type}s"
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
require 'sa2'
|
3
|
+
|
4
|
+
class EnrichmentDb::Geo::SA1 < EnrichmentDb::Geo::Region
|
5
|
+
def self.fields
|
6
|
+
'id, state_id, sa4_id, sa3_id, sa2_id'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.scale
|
10
|
+
10
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parent_class
|
14
|
+
EnrichmentDb::Geo::SA2
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
require 'sa3'
|
3
|
+
|
4
|
+
class EnrichmentDb::Geo::SA2 < EnrichmentDb::Geo::Region
|
5
|
+
def self.fields
|
6
|
+
'id, name, state_id, sa4_id, sa3_id'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.scale
|
10
|
+
11
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parent_class
|
14
|
+
EnrichmentDb::Geo::SA3
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
require 'sa4'
|
3
|
+
|
4
|
+
class EnrichmentDb::Geo::SA3 < EnrichmentDb::Geo::Region
|
5
|
+
def self.fields
|
6
|
+
'id, name, state_id, sa4_id'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.scale
|
10
|
+
14
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parent_class
|
14
|
+
EnrichmentDb::Geo::SA4
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
+
require 'state'
|
3
|
+
|
4
|
+
class EnrichmentDb::Geo::SA4 < EnrichmentDb::Geo::Region
|
5
|
+
def self.fields
|
6
|
+
'id, name, state_id'
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.scale
|
10
|
+
15
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parent_class
|
14
|
+
EnrichmentDb::Geo::State
|
15
|
+
end
|
16
|
+
end
|
data/test/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../test_helper"
|
2
|
+
|
3
|
+
describe EnrichmentDb::Geo::Locator do
|
4
|
+
it 'should find id from a hash of hashes' do
|
5
|
+
id = 2
|
6
|
+
data = { 'c' => { 'id' => 1, 'b_id' => id }, 'b' => { 'id' => 3 } }
|
7
|
+
region_type = 'b'
|
8
|
+
result = EnrichmentDb::Geo::Locator.find_id(data, region_type)
|
9
|
+
assert_equal id, result
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should correctly format a has to a latlong' do
|
13
|
+
lat = 10
|
14
|
+
long = 180
|
15
|
+
lat_long = { 'lat' => lat, 'long' => long }
|
16
|
+
geohash = EnrichmentDb::Geo::Locator.format_geo(lat_long)
|
17
|
+
assert_equal 'xczbzurypzpg', geohash
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should break as the lat long format is incorrect' do
|
21
|
+
lat = 10
|
22
|
+
long = 180
|
23
|
+
lat_long = { 'lat' => lat, 'lon' => long }
|
24
|
+
begin
|
25
|
+
EnrichmentDb::Geo::Locator.format_geo(lat_long)
|
26
|
+
rescue EnrichmentDb::InvalidFormat => e
|
27
|
+
|
28
|
+
else
|
29
|
+
flunk('This should have errored out.')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should ' do
|
34
|
+
geo = 'r1r0g2e'
|
35
|
+
result = EnrichmentDb::Geo::Locator.geo_locate(geo)
|
36
|
+
puts result.smallest_region.inspect
|
37
|
+
puts result.name.inspect
|
38
|
+
puts result.inspect
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<testsuite name="EnrichmentDb::Geo::Locator" skipped="0" failures="0" errors="0" tests="4" assertions="2" time="6.202437521191314">
|
3
|
+
<testcase name="test_0004_should " classname="EnrichmentDb::Geo::Locator" assertions="0" time="6.202266245032661">
|
4
|
+
</testcase>
|
5
|
+
<testcase name="test_0003_should break as the lat long format is incorrect" classname="EnrichmentDb::Geo::Locator" assertions="0" time="6.976805161684752e-05">
|
6
|
+
</testcase>
|
7
|
+
<testcase name="test_0002_should correctly format a has to a latlong" classname="EnrichmentDb::Geo::Locator" assertions="1" time="8.18880507722497e-05">
|
8
|
+
</testcase>
|
9
|
+
<testcase name="test_0001_should find id from a hash of hashes" classname="EnrichmentDb::Geo::Locator" assertions="1" time="1.962005626410246e-05">
|
10
|
+
</testcase>
|
11
|
+
</testsuite>
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'minitest/reporters'
|
5
|
+
require 'minitest/spec'
|
6
|
+
require 'webmock/minitest'
|
7
|
+
require 'faker'
|
8
|
+
require 'factory_girl'
|
9
|
+
|
10
|
+
MiniTest::Reporters.use! [Minitest::Reporters::SpecReporter.new, MiniTest::Reporters::JUnitReporter.new]
|
11
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'enrichment_db')
|
12
|
+
FactoryGirl.find_definitions
|
13
|
+
|
14
|
+
$should_stub = true
|
15
|
+
if $should_stub
|
16
|
+
WebMock.disable_net_connect!
|
17
|
+
else
|
18
|
+
WebMock.allow_net_connect!
|
19
|
+
end
|
20
|
+
|
21
|
+
def stub_get(path)
|
22
|
+
WebMock::API.stub_http_request(:get, request_path(path))
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enrichment_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Wallis
|
@@ -58,7 +58,39 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- ".DS_Store"
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- LICENSE
|
61
65
|
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- enrichment_db.gemspec
|
68
|
+
- lib/enrichment_db.rb
|
69
|
+
- lib/enrichment_db/.DS_Store
|
70
|
+
- lib/enrichment_db/db.rb
|
71
|
+
- lib/enrichment_db/error.rb
|
72
|
+
- lib/enrichment_db/geo.rb
|
73
|
+
- lib/enrichment_db/geo/locator.rb
|
74
|
+
- lib/enrichment_db/geo/postcode.rb
|
75
|
+
- lib/enrichment_db/geo/region.rb
|
76
|
+
- lib/enrichment_db/geo/sa1.rb
|
77
|
+
- lib/enrichment_db/geo/sa2.rb
|
78
|
+
- lib/enrichment_db/geo/sa3.rb
|
79
|
+
- lib/enrichment_db/geo/sa4.rb
|
80
|
+
- lib/enrichment_db/geo/state.rb
|
81
|
+
- lib/enrichment_db/geo/suburb.rb
|
82
|
+
- lib/enrichment_db/version.rb
|
83
|
+
- test/.DS_Store
|
84
|
+
- test/factories/postcode.rb
|
85
|
+
- test/factories/sa1.rb
|
86
|
+
- test/factories/sa2.rb
|
87
|
+
- test/factories/sa3.rb
|
88
|
+
- test/factories/sa4.rb
|
89
|
+
- test/factories/state.rb
|
90
|
+
- test/factories/suburb.rb
|
91
|
+
- test/geo/locator_test.rb
|
92
|
+
- test/reports/TEST-EnrichmentDb-Geo-Locator.xml
|
93
|
+
- test/test_helper.rb
|
62
94
|
homepage: https://github.com/lexerdev/enrichment-db.gem
|
63
95
|
licenses:
|
64
96
|
- MIT
|
@@ -84,4 +116,37 @@ signing_key:
|
|
84
116
|
specification_version: 4
|
85
117
|
summary: Lexer Enrichment Database Gem
|
86
118
|
test_files:
|
119
|
+
- ".DS_Store"
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE
|
87
123
|
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- enrichment_db.gemspec
|
126
|
+
- lib/enrichment_db.rb
|
127
|
+
- lib/enrichment_db/.DS_Store
|
128
|
+
- lib/enrichment_db/db.rb
|
129
|
+
- lib/enrichment_db/error.rb
|
130
|
+
- lib/enrichment_db/geo.rb
|
131
|
+
- lib/enrichment_db/geo/locator.rb
|
132
|
+
- lib/enrichment_db/geo/postcode.rb
|
133
|
+
- lib/enrichment_db/geo/region.rb
|
134
|
+
- lib/enrichment_db/geo/sa1.rb
|
135
|
+
- lib/enrichment_db/geo/sa2.rb
|
136
|
+
- lib/enrichment_db/geo/sa3.rb
|
137
|
+
- lib/enrichment_db/geo/sa4.rb
|
138
|
+
- lib/enrichment_db/geo/state.rb
|
139
|
+
- lib/enrichment_db/geo/suburb.rb
|
140
|
+
- lib/enrichment_db/version.rb
|
141
|
+
- test/.DS_Store
|
142
|
+
- test/factories/postcode.rb
|
143
|
+
- test/factories/sa1.rb
|
144
|
+
- test/factories/sa2.rb
|
145
|
+
- test/factories/sa3.rb
|
146
|
+
- test/factories/sa4.rb
|
147
|
+
- test/factories/state.rb
|
148
|
+
- test/factories/suburb.rb
|
149
|
+
- test/geo/locator_test.rb
|
150
|
+
- test/reports/TEST-EnrichmentDb-Geo-Locator.xml
|
151
|
+
- test/test_helper.rb
|
152
|
+
has_rdoc:
|