worlddb-models 2.2.0 → 2.2.1
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/README.md +9 -0
- data/lib/worlddb/matcher.rb +26 -14
- data/lib/worlddb/version.rb +1 -1
- data/test/test_fixture_matchers_ii.rb +109 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7166c33111b731ecc3e9199970da99ff49b725e
|
4
|
+
data.tar.gz: 230f400cbcc9d7586ffc12558aacdac894ae3947
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e9eeaa6e6803d5ae28d531f805ba38bf93f11c614fbbbd994e2c17321ed2f442376f851277befb1a156625ca8eb33a3991083b0a1d713185ef393dfce16c972
|
7
|
+
data.tar.gz: f7fb67fd482e3909c51fcd7bee5aa8f61da3dc34c270bb17021d3775ccff7518687f98a606310901d895d39626b722f6f89ede93d4c2989bbf13c33fecb7745e
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -11,6 +11,15 @@ worlddb-models gem - world.db schema 'n' models for easy (re)use
|
|
11
11
|
|
12
12
|
## Usage Models
|
13
13
|
|
14
|
+
Class Model Diagrams
|
15
|
+
|
16
|
+
![](worlddb-models.png)
|
17
|
+
|
18
|
+
Everything is a place.
|
19
|
+
|
20
|
+
![](worlddb-models-place.png)
|
21
|
+
|
22
|
+
|
14
23
|
`Country` Model - Example:
|
15
24
|
|
16
25
|
at = Country.find_by! key: 'at'
|
data/lib/worlddb/matcher.rb
CHANGED
@@ -4,6 +4,18 @@ module WorldDb
|
|
4
4
|
|
5
5
|
module Matcher
|
6
6
|
|
7
|
+
WORLD_COUNTRY_CODE_PATTERN = '([a-z]{2,3})'
|
8
|
+
WORLD_COUNTRY_CLASSIC_PATTERN = "#{WORLD_COUNTRY_CODE_PATTERN}-[^\\/]+" ## note: if you use "" need to double escape backslash!!!
|
9
|
+
WORLD_COUNTRY_MODERN_PATTERN = "[0-9]+--#{WORLD_COUNTRY_CODE_PATTERN}-[^\\/]+" ## note: if you use "" need to double escape backslash!!!
|
10
|
+
|
11
|
+
WORLD_REGION_CODE_PATTERN = '([a-z]{1,3})'
|
12
|
+
WORLD_REGION_CLASSIC_PATTERN = "#{WORLD_REGION_CODE_PATTERN}-[^\\/]+"
|
13
|
+
WORLD_REGION_MODERN_PATTERN = "[0-9]+--#{WORLD_REGION_CODE_PATTERN}-[^\\/]+"
|
14
|
+
|
15
|
+
## allow optional folders -- TODO: add restriction ?? e.g. must be 4+ alphas ???
|
16
|
+
WORLD_OPT_FOLDERS_PATTERN = "(?:\\/[^\\/]+)*" ## check: use double \\ or just \ ??
|
17
|
+
|
18
|
+
|
7
19
|
def match_xxx_for_country( name, xxx ) # xxx e.g. cities|regions|beers|breweries
|
8
20
|
# auto-add required country code (from folder structure)
|
9
21
|
# note: always let match_xxx_for_country_n_region go first
|
@@ -14,16 +26,16 @@ module Matcher
|
|
14
26
|
##
|
15
27
|
## todo: add $-anchor at the end of pattern - why? why not?? (will include .txt or .yaml??)
|
16
28
|
|
17
|
-
if name =~ /(?:^|\/)
|
18
|
-
name =~ /(?:^|\/)
|
19
|
-
name =~ /(?:^|\/)
|
20
|
-
name =~ /(?:^|\/)
|
21
|
-
name =~ /(?:^|\/)
|
29
|
+
if name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{xxx_pattern}/ || # (1)
|
30
|
+
name =~ /(?:^|\/)#{WORLD_COUNTRY_MODERN_PATTERN}\/#{xxx_pattern}/ || # (2)
|
31
|
+
name =~ /(?:^|\/)#{WORLD_COUNTRY_CODE_PATTERN}\/#{xxx_pattern}/ || # (3)
|
32
|
+
name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/[0-9]+--[^\/]+\/#{xxx_pattern}/ || # (4)
|
33
|
+
name =~ /(?:^|\/)#{WORLD_COUNTRY_CODE_PATTERN}-[^\/]+--#{xxx}/ # (5)
|
22
34
|
|
23
35
|
country_key = $1.dup
|
24
36
|
yield( country_key )
|
25
37
|
true # bingo - match found
|
26
|
-
|
38
|
+
|
27
39
|
######
|
28
40
|
# (1) new style: e.g. /at-austria/beers or ^at-austria!/cities
|
29
41
|
#
|
@@ -51,16 +63,16 @@ module Matcher
|
|
51
63
|
# at-austria!/1--n-niederoesterreich--eastern/wagram--wagram--wines
|
52
64
|
|
53
65
|
# note: allow /cities and /1--hokkaido--cities and /hokkaido--cities too
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
66
|
+
# note: allow anything before xxx for now -- use/require dash (--) why, why not??
|
67
|
+
oldoldold_xxx_pattern = "(?:#{xxx}|[^\\/]+--#{xxx})"
|
68
|
+
xxx_pattern = "(?:#{xxx}|[^\\/]+#{xxx})" # note: double escape \\ required for backslash
|
69
|
+
|
58
70
|
## note: for now only (style #2) n (style #3) that is long region allow opt folders
|
59
71
|
|
60
|
-
if name =~ /(?:^|\/)
|
61
|
-
name =~ /(?:^|\/)
|
62
|
-
name =~ /(?:^|\/)
|
63
|
-
name =~ /(?:^|\/)
|
72
|
+
if name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_REGION_CLASSIC_PATTERN}#{WORLD_OPT_FOLDERS_PATTERN}\/#{xxx_pattern}/ || # (1)
|
73
|
+
name =~ /(?:^|\/)#{WORLD_COUNTRY_MODERN_PATTERN}\/#{WORLD_REGION_MODERN_PATTERN}#{WORLD_OPT_FOLDERS_PATTERN}\/#{xxx_pattern}/ || # (2)
|
74
|
+
name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_REGION_MODERN_PATTERN}#{WORLD_OPT_FOLDERS_PATTERN}\/#{xxx_pattern}/ || # (3)
|
75
|
+
name =~ /(?:^|\/)#{WORLD_COUNTRY_MODERN_PATTERN}\/#{WORLD_REGION_CLASSIC_PATTERN}\/#{xxx_pattern}/ # (4)
|
64
76
|
|
65
77
|
#######
|
66
78
|
# nb: country must start name (^) or coming after / e.g. europe/at-austria/...
|
data/lib/worlddb/version.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_fixture_matchers_ii.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestFixtureMatchersII < MiniTest::Test
|
12
|
+
|
13
|
+
include WorldDb::Matcher
|
14
|
+
|
15
|
+
def test_country_n_region_breweries_franken
|
16
|
+
breweries_franken = [
|
17
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/100_000+_breweries',
|
18
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/20_000+-breweries',
|
19
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/coburger-land--breweries',
|
20
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/fichtelgebirge--breweries',
|
21
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/fraenkische-schweiz--breweries',
|
22
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/frankenwald--breweries',
|
23
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/hassberge--breweries',
|
24
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/steigerwald--breweries',
|
25
|
+
'de-deutschland/by-bayern/franken!/2--mittelfranken/breweries',
|
26
|
+
'de-deutschland/by-bayern/franken!/2--mittelfranken/breweries_20_000+',
|
27
|
+
'de-deutschland/by-bayern/franken!/3--unterfranken/breweries',
|
28
|
+
'de-deutschland/by-bayern/franken!/3--unterfranken/breweries_100_000+',
|
29
|
+
'de-deutschland/by-bayern/franken!/3--unterfranken/breweries_20_000+',
|
30
|
+
]
|
31
|
+
assert_match_xxx_for_country_n_region( breweries_franken, 'breweries', 'de', 'by' )
|
32
|
+
end # method test_country_n_region_breweries
|
33
|
+
|
34
|
+
def test_country_n_region_breweries_bayern
|
35
|
+
breweries_bayern = [
|
36
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/breweries_(l)',
|
37
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/breweries_(m)',
|
38
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/breweries',
|
39
|
+
'de-deutschland/3--by-bayern!/2--niederbayern/breweries',
|
40
|
+
'de-deutschland/3--by-bayern!/2--niederbayern/breweries_100_000+',
|
41
|
+
'de-deutschland/3--by-bayern!/2--niederbayern/breweries_20_000+',
|
42
|
+
'de-deutschland/3--by-bayern!/3--oberpfalz/breweries',
|
43
|
+
'de-deutschland/3--by-bayern!/3--oberpfalz/breweries_100_000+',
|
44
|
+
'de-deutschland/3--by-bayern!/3--oberpfalz/breweries_20_000+',
|
45
|
+
'de-deutschland/3--by-bayern!/4--schwaben/breweries',
|
46
|
+
'de-deutschland/3--by-bayern!/4--schwaben/breweries_100_000+',
|
47
|
+
'de-deutschland/3--by-bayern!/4--schwaben/breweries_20_000+',
|
48
|
+
]
|
49
|
+
assert_match_xxx_for_country_n_region( breweries_bayern, 'breweries', 'de', 'by' )
|
50
|
+
end # method test_country_n_region_breweries
|
51
|
+
|
52
|
+
|
53
|
+
def test_country_n_region_brewpubs_franken
|
54
|
+
brewpubs_franken = [
|
55
|
+
'de-deutschland/by-bayern/franken!/3--unterfranken/brewpubs',
|
56
|
+
]
|
57
|
+
assert_match_xxx_for_country_n_region( brewpubs_franken, 'brewpubs', 'de', 'by' )
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_country_n_region_brewpubs_bayern
|
61
|
+
brewpubs_bayern = [
|
62
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/brewpubs',
|
63
|
+
'de-deutschland/3--by-bayern!/2--niederbayern/brewpubs',
|
64
|
+
'de-deutschland/3--by-bayern!/3--oberpfalz/brewpubs',
|
65
|
+
'de-deutschland/3--by-bayern!/4--schwaben/brewpubs',
|
66
|
+
]
|
67
|
+
assert_match_xxx_for_country_n_region( brewpubs_bayern, 'brewpubs', 'de', 'by' )
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def test_country_n_region_beers_franken
|
72
|
+
beers_franken = [
|
73
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/100_000+_beers',
|
74
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/beers',
|
75
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/fichtelgebirge-bayreuth--beers',
|
76
|
+
'de-deutschland/by-bayern/franken!/1--oberfranken/steigerwald-bamberg--beers',
|
77
|
+
'de-deutschland/by-bayern/franken!/3--unterfranken/beers_100_000+',
|
78
|
+
]
|
79
|
+
assert_match_xxx_for_country_n_region( beers_franken, 'beers', 'de', 'by' )
|
80
|
+
end # method test_country_n_region_beers
|
81
|
+
|
82
|
+
def test_country_n_region_beers_bayern
|
83
|
+
beers_bayern = [
|
84
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/beers--muenchen',
|
85
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/beers_l',
|
86
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/beers_m',
|
87
|
+
'de-deutschland/3--by-bayern!/1--oberbayern/beers',
|
88
|
+
'de-deutschland/3--by-bayern!/2--niederbayern/beers',
|
89
|
+
'de-deutschland/3--by-bayern!/2--niederbayern/beers_100_000+',
|
90
|
+
'de-deutschland/3--by-bayern!/3--oberpfalz/beers',
|
91
|
+
'de-deutschland/3--by-bayern!/3--oberpfalz/beers_100_000+',
|
92
|
+
'de-deutschland/3--by-bayern!/4--schwaben/beers_100_000+',
|
93
|
+
]
|
94
|
+
assert_match_xxx_for_country_n_region( beers_bayern, 'beers', 'de', 'by' )
|
95
|
+
end # method test_country_n_region_beers
|
96
|
+
|
97
|
+
|
98
|
+
private
|
99
|
+
def assert_match_xxx_for_country_n_region( ary, xxx, expected_country_key, expected_region_key )
|
100
|
+
ary.each do |name|
|
101
|
+
found = match_xxx_for_country_n_region( name, xxx ) do |country_key,region_key|
|
102
|
+
assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
|
103
|
+
assert_equal region_key, expected_region_key, "#{expected_region_key} expected is #{region_key}"
|
104
|
+
end
|
105
|
+
assert found, "no match for '#{name}'"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end # class TestFixtureMatchersII
|
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.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: props
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/worlddb/version.rb
|
213
213
|
- test/helper.rb
|
214
214
|
- test/test_fixture_matchers.rb
|
215
|
+
- test/test_fixture_matchers_ii.rb
|
215
216
|
- test/test_model_city.rb
|
216
217
|
- test/test_model_comp.rb
|
217
218
|
- test/test_model_country.rb
|
@@ -250,3 +251,4 @@ test_files:
|
|
250
251
|
- test/test_fixture_matchers.rb
|
251
252
|
- test/test_model_country.rb
|
252
253
|
- test/test_model_region.rb
|
254
|
+
- test/test_fixture_matchers_ii.rb
|