worlddb 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -9,6 +9,7 @@ lib/worlddb/cli/opts.rb
9
9
  lib/worlddb/console.rb
10
10
  lib/worlddb/data/fixtures.rb
11
11
  lib/worlddb/deleter.rb
12
+ lib/worlddb/matcher.rb
12
13
  lib/worlddb/models/city.rb
13
14
  lib/worlddb/models/continent.rb
14
15
  lib/worlddb/models/country.rb
@@ -0,0 +1,78 @@
1
+ # encoding: UTF-8
2
+
3
+ module WorldDb
4
+
5
+ module Matcher
6
+
7
+ def match_xxx_for_country( name, xxx, blk ) # xxx e.g. cities|regions|beers|breweries
8
+ if name =~ /(?:^|\/)([a-z]{2})-[^\/]+\/#{xxx}/
9
+ # new style: e.g. /at-austria/beers or ^at-austria!/beers
10
+ # auto-add required country code (from folder structure)
11
+ country_key = $1.dup
12
+ blk.call( country_key )
13
+ true # bingo - match found
14
+ elsif name =~ /\/([a-z]{2})\/#{xxx}/
15
+ # classic style: e.g. /at/beers (europe/at/beers)
16
+ # auto-add required country code (from folder structure)
17
+ country_key = $1.dup
18
+ blk.call( country_key )
19
+ true
20
+ else
21
+ false # no match found
22
+ end
23
+ end
24
+
25
+ def match_xxx_for_country_n_region( name, xxx, blk ) # xxx e.g. beers|breweries
26
+ if name =~ /(?:^|\/)([a-z]{2})-[^\/]+\/([a-z]{1,2})-[^\/]+\/#{xxx}/
27
+ # new style: e.g. /at-austria/w-wien/beers or
28
+ # ^at-austria!/w-wien/beers
29
+ # nb: country must start name (^) or coming after / e.g. europe/at-austria/...
30
+ #
31
+ # auto-add required country n region code (from folder structure)
32
+ country_key = $1.dup
33
+ region_key = $2.dup
34
+ blk.call( country_key, region_key )
35
+ true # bingo - match found
36
+ else
37
+ false # no match found
38
+ end
39
+ end
40
+
41
+
42
+ def match_cities_for_country( name, &blk )
43
+ match_xxx_for_country( name, 'cities', blk )
44
+ end
45
+
46
+ def match_regions_for_country( name, &blk )
47
+ match_xxx_for_country( name, 'regions', blk )
48
+ end
49
+
50
+ def match_regions_abbr_for_country( name, &blk )
51
+ match_xxx_for_country( name, 'regions\.abbr', blk ) # NB: . gets escaped for regex, that is, \.
52
+ end
53
+
54
+ def match_regions_iso_for_country( name, &blk ) # NB: . gets escaped for regex, that is, \.
55
+ match_xxx_for_country( name, 'regions\.iso', blk )
56
+ end
57
+
58
+ def match_regions_nuts_for_country( name, &blk ) # NB: . gets escaped for regex, that is, \.
59
+ match_xxx_for_country( name, 'regions\.nuts', blk )
60
+ end
61
+
62
+
63
+ def match_countries_for_continent( name )
64
+ if name =~ /^([a-z][a-z\-_]+[a-z])\/countries/ # e.g. africa/countries or america/countries
65
+ ### NB: continent changed to regions (e.g. middle-east, caribbean, north-america, etc.)
66
+ ## auto-add continent (from folder structure) as tag
67
+ ## fix: allow dash/hyphen/minus in tag
68
+ continent = $1.dup
69
+ yield( continent )
70
+ true
71
+ else
72
+ false # no match found
73
+ end
74
+ end
75
+
76
+ end # module Matcher
77
+
78
+ end # module WorldDb
@@ -10,10 +10,13 @@ class Reader
10
10
  ## make models available in sportdb module by default with namespace
11
11
  # e.g. lets you use City instead of Models::City
12
12
  include WorldDb::Models
13
-
13
+
14
14
 
15
15
  ## value helpers e.g. is_year?, is_taglist? etc.
16
16
  include TextUtils::ValueHelper
17
+
18
+ include WorldDb::Matcher # e.g. match_cities_for_country, match_regions_for_country, etc.
19
+
17
20
 
18
21
  attr_reader :include_path
19
22
 
@@ -77,23 +80,29 @@ class Reader
77
80
  load_xxx( 'motor', name )
78
81
  elsif name =~ /^tag.*\.(\d)$/
79
82
  load_tags( name, :grade => $1.to_i )
80
- elsif name =~ /^([a-z][a-z\-_]+[a-z])\/countries/ # e.g. africa/countries or america/countries
81
- ### NB: continent changed to regions (e.g. middle-east, caribbean, north-america, etc.)
82
- ## auto-add continent (from folder structure) as tag
83
- ## fix: allow dash/hyphen/minus in tag
84
- load_countries( name, :tags => $1.tr('-', '_') )
85
- elsif name =~ /\/([a-z]{2})\/cities/
86
- ## auto-add required country code (from folder structure)
87
- load_cities( $1, name )
88
- elsif name =~ /\/([a-z]{2})\/regions\.abbr/
89
- load_regions_xxx( $1, 'abbr', name )
90
- elsif name =~ /\/([a-z]{2})\/regions\.iso/
91
- load_regions_xxx( $1, 'iso', name )
92
- elsif name =~ /\/([a-z]{2})\/regions\.nuts/
93
- load_regions_xxx( $1, 'nuts', name )
94
- elsif name =~ /\/([a-z]{2})\/regions/
95
- ## auto-add required country code (from folder structure)
96
- load_regions( $1, name )
83
+ elsif match_countries_for_continent( name ) do |continent| # # e.g. africa/countries or america/countries
84
+ ### NB: continent changed to regions (e.g. middle-east, caribbean, north-america, etc.)
85
+ ## auto-add continent (from folder structure) as tag
86
+ ## fix: allow dash/hyphen/minus in tag
87
+ load_countries( name, :tags => continent.tr('-', '_') )
88
+ end
89
+ elsif match_cities_for_country( name ) do |country_key| # name =~ /\/([a-z]{2})\/cities/
90
+ ## auto-add required country code (from folder structure)
91
+ load_cities( country_key, name )
92
+ end
93
+ elsif match_regions_abbr_for_country( name ) do |country_key| # name =~ /\/([a-z]{2})\/regions\.abbr/
94
+ load_regions_xxx( country_key, 'abbr', name )
95
+ end
96
+ elsif match_regions_iso_for_country( name ) do |country_key| # name =~ /\/([a-z]{2})\/regions\.iso/
97
+ load_regions_xxx( country_key, 'iso', name )
98
+ end
99
+ elsif match_regions_nuts_for_country( name ) do |country_key| # name =~ /\/([a-z]{2})\/regions\.nuts/
100
+ load_regions_xxx( country_key, 'nuts', name )
101
+ end
102
+ elsif match_regions_for_country( name ) do |country_key| # name =~ /\/([a-z]{2})\/regions/
103
+ ## auto-add required country code (from folder structure)
104
+ load_regions( country_key, name )
105
+ end
97
106
  else
98
107
  logger.error "unknown world.db fixture type >#{name}<"
99
108
  # todo/fix: exit w/ error
@@ -101,6 +110,7 @@ class Reader
101
110
  end
102
111
 
103
112
 
113
+
104
114
  def load_countries( name, more_attribs={} )
105
115
  load_fixtures_for( Country, name, more_attribs )
106
116
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module WorldDb
3
- VERSION = '1.7.1' # sync version w/ sport.db - why? why not?
3
+ VERSION = '1.7.2' # sync version w/ sport.db - why? why not?
4
4
  end
5
5
 
6
6
  ###########################################
data/lib/worlddb.rb CHANGED
@@ -37,6 +37,7 @@ require 'worlddb/models/tagging'
37
37
  require 'worlddb/models/lang'
38
38
  require 'worlddb/models/usage'
39
39
  require 'worlddb/schema' # NB: requires worlddb/models (include WorldDB::Models)
40
+ require 'worlddb/matcher'
40
41
  require 'worlddb/reader'
41
42
  require 'worlddb/deleter'
42
43
  require 'worlddb/stats'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-20 00:00:00.000000000 Z
12
+ date: 2013-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: textutils
16
- requirement: &78717170 !ruby/object:Gem::Requirement
16
+ requirement: &75034640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *78717170
24
+ version_requirements: *75034640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commander
27
- requirement: &78716950 !ruby/object:Gem::Requirement
27
+ requirement: &75034420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 4.1.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *78716950
35
+ version_requirements: *75034420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activerecord
38
- requirement: &78716740 !ruby/object:Gem::Requirement
38
+ requirement: &75034210 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.2'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *78716740
46
+ version_requirements: *75034210
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &78716520 !ruby/object:Gem::Requirement
49
+ requirement: &75033990 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '3.10'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *78716520
57
+ version_requirements: *75033990
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &78716300 !ruby/object:Gem::Requirement
60
+ requirement: &75033770 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *78716300
68
+ version_requirements: *75033770
69
69
  description: worlddb - world.db command line tool
70
70
  email: opensport@googlegroups.com
71
71
  executables:
@@ -85,6 +85,7 @@ files:
85
85
  - lib/worlddb/console.rb
86
86
  - lib/worlddb/data/fixtures.rb
87
87
  - lib/worlddb/deleter.rb
88
+ - lib/worlddb/matcher.rb
88
89
  - lib/worlddb/models/city.rb
89
90
  - lib/worlddb/models/continent.rb
90
91
  - lib/worlddb/models/country.rb