worlddb-models 2.3.2 → 2.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/lib/worlddb/models/name.rb +2 -0
- data/lib/worlddb/models/place.rb +4 -0
- data/lib/worlddb/readers/state_tree.rb +41 -3
- data/lib/worlddb/version.rb +1 -1
- data/test/test_state_tree_reader_name_finder.rb +67 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fd3e4a124d077f78bb176f7a6bc5b57ae15e5a9
|
4
|
+
data.tar.gz: 4cc9e212e7fb37bb21d557a262698411daacb754
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 563ffc1f779a443c5126c41c8ab6385a653a74634cacbbc7d6a397f17d83be00c73b40356c1d2c7878122f8ad96138d71a5dbef934b4fa3123958add12319534
|
7
|
+
data.tar.gz: 1bf7aa7c891b4d404a60a08d3e24abecaeb042a71758f1463c5704104bd85ca1c2d0f06e0e1131d24de083f4d98e8736894f8fd60116f114238e2cbb3d03db04
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ Hoe.spec 'worlddb-models' do
|
|
17
17
|
self.extra_deps = [
|
18
18
|
['props', '>= 1.1.2'], # settings / prop(ertie)s / env / INI
|
19
19
|
['logutils', '>= 0.6.1'], # logging
|
20
|
-
['textutils', '>= 1.3.
|
20
|
+
['textutils', '>= 1.3.1'],
|
21
21
|
|
22
22
|
['tagutils', '>= 0.3.0'], # tags n categories for activerecord
|
23
23
|
['activerecord-utils', '>= 0.2.0'],
|
data/lib/worlddb/models/name.rb
CHANGED
data/lib/worlddb/models/place.rb
CHANGED
@@ -7,6 +7,10 @@ class Place < ActiveRecord::Base
|
|
7
7
|
|
8
8
|
## todo: depending on type
|
9
9
|
## has_one continent, country, state, city etc.
|
10
|
+
has_one :state, class_name: 'State', foreign_key: 'place_id'
|
11
|
+
has_one :county, class_name: 'County', foreign_key: 'place_id'
|
12
|
+
has_one :muni, class_name: 'Muni', foreign_key: 'place_id'
|
13
|
+
## add more types..
|
10
14
|
|
11
15
|
end # class Place
|
12
16
|
|
@@ -36,17 +36,55 @@ class StateTreeReader < ReaderBaseWithMoreAttribs
|
|
36
36
|
puts " #{names.join( ' › ' )}:"
|
37
37
|
puts " key: >#{node.key}<, level: >#{node.level}<, value: >#{node.value}<"
|
38
38
|
|
39
|
+
## use name for lookup - use where() to find - might match more than 1 record!!
|
40
|
+
## todo/fix: check for multiple or no matches!!!
|
41
|
+
## todo/fix: check how to add state.id scope (and country.id scope) etc.
|
42
|
+
## add state.id to name - why? why not?
|
43
|
+
## move finders to name model for reuse (and testing) - why? why not ??
|
39
44
|
if node.level == state_level # 1
|
40
|
-
rec = State.where( "name like '#{node.value}%'" ).first
|
45
|
+
## was: rec = State.where( "name like '#{node.value}%'" ).first
|
46
|
+
names = Name.joins(
|
47
|
+
:place => :state
|
48
|
+
).find_by(
|
49
|
+
:name => node.value,
|
50
|
+
:place_kind => 'STAT',
|
51
|
+
:'states.country_id' => country.id )
|
52
|
+
rec = if names.nil?
|
53
|
+
nil
|
54
|
+
else
|
55
|
+
names.place.state # get first record; fix: use where instead of find_by etc.
|
56
|
+
end
|
41
57
|
elsif node.level == part_level # 2
|
42
58
|
state = stack[0]
|
43
59
|
rec = Part.where( "name like '#{node.value}%' AND state_id = #{state.id}" ).first
|
44
60
|
elsif node.level == county_level # 2 or 3
|
45
61
|
state = stack[0]
|
46
|
-
rec = County.where( "name like '#{node.value}%' AND state_id = #{state.id}" ).first
|
62
|
+
## was: rec = County.where( "name like '#{node.value}%' AND state_id = #{state.id}" ).first
|
63
|
+
names = Name.joins(
|
64
|
+
:place => :county
|
65
|
+
).find_by(
|
66
|
+
:name => node.value,
|
67
|
+
:place_kind => 'COUN',
|
68
|
+
:'counties.state_id' => state.id )
|
69
|
+
rec = if names.nil?
|
70
|
+
nil
|
71
|
+
else
|
72
|
+
names.place.county # get first record
|
73
|
+
end
|
47
74
|
elsif node.level == muni_level # 3 or 4
|
48
75
|
state = stack[0]
|
49
|
-
rec = Muni.where( "name like '#{node.value}%' AND state_id = #{state.id}" ).first
|
76
|
+
## was: rec = Muni.where( "name like '#{node.value}%' AND state_id = #{state.id}" ).first
|
77
|
+
names = Name.joins(
|
78
|
+
:place => :muni
|
79
|
+
).find_by(
|
80
|
+
:name => node.value,
|
81
|
+
:place_kind => 'MUNI',
|
82
|
+
:'munis.state_id' => state.id )
|
83
|
+
rec = if names.nil?
|
84
|
+
nil
|
85
|
+
else
|
86
|
+
names.place.muni # get first record
|
87
|
+
end
|
50
88
|
elsif node.level == city_level # 4 or 5
|
51
89
|
## note: city requires country scope for lookup
|
52
90
|
## todo/fix: how to deal with cities with the same name
|
data/lib/worlddb/version.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_state_tree_reader_name_finder.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestStateTreeReaderNameFinder < MiniTest::Test
|
11
|
+
|
12
|
+
def setup
|
13
|
+
# delete all countries, states, cities in in-memory only db
|
14
|
+
WorldDb.delete!
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_at
|
18
|
+
at = Country.create!( key: 'at',
|
19
|
+
name: 'Austria',
|
20
|
+
code: 'AUT',
|
21
|
+
pop: 0,
|
22
|
+
area: 0 )
|
23
|
+
|
24
|
+
reader = WorldDb::Reader.new( "#{WorldDb.root}/test/data/at-austria" )
|
25
|
+
reader.load_setup( 'setups/adm' )
|
26
|
+
|
27
|
+
n = State.find_by!( key: 'n' )
|
28
|
+
|
29
|
+
|
30
|
+
## find counties w/ state_id using names
|
31
|
+
names = Name.joins( :place => :county ).where(
|
32
|
+
:name => 'Horn',
|
33
|
+
:place_kind => 'COUN',
|
34
|
+
:'counties.state_id' => n.id )
|
35
|
+
## results in:
|
36
|
+
## SELECT "names".* FROM "names"
|
37
|
+
## INNER JOIN "places" ON "places"."id" = "names"."place_id"
|
38
|
+
## INNER JOIN "counties" ON "counties"."place_id" = "places"."id"
|
39
|
+
## WHERE "names"."name" = ?
|
40
|
+
## AND "names"."place_kind" = ?
|
41
|
+
## AND "counties"."state_id" = 2
|
42
|
+
## [["name", "Horn"], ["place_kind", "COUN"]]
|
43
|
+
|
44
|
+
pp names
|
45
|
+
|
46
|
+
|
47
|
+
## find munies w/ state_id using names
|
48
|
+
names = Name.joins( :place => :muni ).where(
|
49
|
+
:name => 'Horn',
|
50
|
+
:place_kind => 'MUNI',
|
51
|
+
:'munis.state_id' => n.id )
|
52
|
+
|
53
|
+
## results in:
|
54
|
+
## SELECT "names".* FROM "names"
|
55
|
+
## INNER JOIN "places" ON "places"."id" = "names"."place_id"
|
56
|
+
## INNER JOIN "munis" ON "munis"."place_id" = "places"."id"
|
57
|
+
## WHERE "names"."name" = ?
|
58
|
+
## AND "names"."place_kind" = ?
|
59
|
+
## AND "munis"."state_id" = 2
|
60
|
+
## [["name", "Horn"], ["place_kind", "MUNI"]]
|
61
|
+
|
62
|
+
pp names
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end # class TestStateTreeReaderNameFinder
|
67
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worlddb-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.
|
4
|
+
version: 2.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: props
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.3.
|
47
|
+
version: 1.3.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.3.
|
54
|
+
version: 1.3.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: tagutils
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- test/test_report_country.rb
|
251
251
|
- test/test_state_tree_reader_at.rb
|
252
252
|
- test/test_state_tree_reader_de.rb
|
253
|
+
- test/test_state_tree_reader_name_finder.rb
|
253
254
|
homepage: https://github.com/worlddb/world.db.models
|
254
255
|
licenses:
|
255
256
|
- Public Domain
|
@@ -288,6 +289,7 @@ test_files:
|
|
288
289
|
- test/test_model_state.rb
|
289
290
|
- test/test_model_city.rb
|
290
291
|
- test/test_fixture_matchers.rb
|
292
|
+
- test/test_state_tree_reader_name_finder.rb
|
291
293
|
- test/test_model_country.rb
|
292
294
|
- test/test_parse_city.rb
|
293
295
|
- test/test_report_country.rb
|