beerdb 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/beerdb/reader.rb +80 -25
  2. data/lib/beerdb/version.rb +1 -1
  3. metadata +11 -11
data/lib/beerdb/reader.rb CHANGED
@@ -2,12 +2,79 @@
2
2
 
3
3
  module BeerDb
4
4
 
5
+
6
+ #
7
+ # rename n split TextUtils::ValueHelper into
8
+ # WorldDb::Matcher - match_country, etc.
9
+ # BeerDb::Matcher - match_brewery, etc.
10
+
11
+
12
+ ## todo: move to worlddb for reuse!!! - find a better name?
13
+
14
+ module FixtureMatcher
15
+
16
+ def match_xxx_for_country( name, xxx ) # xxx e.g. beers|breweries
17
+ if name =~ /(?:^|\/)([a-z]{2})-[^\/]+\/#{xxx}/
18
+ # new style: e.g. /at-austria/beers or ^at-austria!/beers
19
+ # auto-add required country code (from folder structure)
20
+ country_key = $1.dup
21
+ yield( country_key )
22
+ true # bingo - match found
23
+ elsif name =~ /\/([a-z]{2})\/#{xxx}/
24
+ # classic style: e.g. /at/beers (europe/at/beers)
25
+ # auto-add required country code (from folder structure)
26
+ country_key = $1.dup
27
+ yield( country_key )
28
+ true
29
+ else
30
+ false # no match found
31
+ end
32
+ end
33
+
34
+ def match_xxx_for_country_n_region( name, xxx ) # xxx e.g. beers|breweries
35
+ if name =~ /(?:^|\/)([a-z]{2})-[^\/]+\/([a-z]{1,2})-[^\/]+\/#{xxx}/
36
+ # new style: e.g. /at-austria/w-wien/beers or
37
+ # ^at-austria!/w-wien/beers
38
+ # nb: country must start name (^) or coming after / e.g. europe/at-austria/...
39
+ #
40
+ # auto-add required country n region code (from folder structure)
41
+ country_key = $1.dup
42
+ region_key = $2.dup
43
+ yield( country_key, region_key )
44
+ true # bingo - match found
45
+ else
46
+ false # no match found
47
+ end
48
+ end
49
+
50
+
51
+ def match_beers_for_country( name, &block )
52
+ match_xxx_for_country( name, 'beers', block )
53
+ end
54
+
55
+ def match_beers_for_country_n_region( name, &block )
56
+ match_xxx_for_country_n_region( name, 'beers', block )
57
+ end
58
+
59
+ def match_breweries_for_country( name, &block )
60
+ match_xxx_for_country( name, 'breweries', block )
61
+ end
62
+
63
+ def match_breweries_for_country_n_region( name, &block )
64
+ match_xxx_for_country_n_region( name, 'breweries', block )
65
+ end
66
+
67
+
68
+ end # module FixtureMatcher
69
+
5
70
  class Reader
6
71
 
7
72
  include LogUtils::Logging
8
73
 
9
74
  include BeerDb::Models
10
75
 
76
+ include FixtureMatcher # see above
77
+
11
78
  attr_reader :include_path
12
79
 
13
80
 
@@ -31,35 +98,23 @@ class Reader
31
98
 
32
99
  def load( name )
33
100
 
34
- if name =~ /\/([a-z]{2})\/beers/
35
- # classic style: e.g. /at/beers
36
- # auto-add required country code (from folder structure)
37
- load_beers_for_country( $1, name )
38
- elsif name =~ /\/([a-z]{2})-[^\/]+\/([a-z]{1,2})-[^\/]+\/beers/
39
- # new style: e.g. /at-austria/w-wien/beers
40
- # auto-add required country n region code (from folder structure)
41
- load_beers_for_country_n_region( $1, $2, name )
42
- elsif name =~ /\/([a-z]{2})-[^\/]+\/beers/
43
- # new style: e.g. /at-austria/beers
44
- # auto-add required country code (from folder structure)
45
- load_beers_for_country( $1, name )
46
- elsif name =~ /\.hl$/ # e.g. breweries.hl # NB: must end w/ .hl
101
+ if name =~ /\.hl$/ # e.g. breweries.hl # NB: must end w/ .hl
47
102
  load_brewery_prod( name )
48
103
  elsif name =~ /\/([a-z]{2})\.wikipedia/ # e.g. de.wikipedia
49
104
  # auto-add required lang e.g. de or en etc.
50
105
  load_brewery_wikipedia( $1, name )
51
- elsif name =~ /\/([a-z]{2})-[^\/]+\/([a-z]{1,2})-[^\/]+\/breweries/
52
- # new style: e.g. /at-austria/w-wien/breweries
53
- # auto-add required country n region code (from folder structure)
54
- load_breweries_for_country_n_region( $1, $2, name )
55
- elsif name =~ /\/([a-z]{2})-[^\/]+\/breweries/
56
- # new style: e.g. /at-austria/breweries
57
- # auto-add required country (from folder structure)
58
- load_breweries_for_country( $1, name )
59
- elsif name =~ /\/([a-z]{2})\/breweries/
60
- # classic style: e.g. /at/breweries
61
- # auto-add required country code (from folder structure)
62
- load_breweries_for_country( $1, name )
106
+ elsif match_beers_for_country_n_region( name ) do |country_key, region_key|
107
+ load_beers_for_country_n_region( country_key, region_key, name )
108
+ end
109
+ elsif match_beers_for_country( name ) do |country_key|
110
+ load_beers_for_country( country_key, name )
111
+ end
112
+ elsif match_breweries_for_country_n_region( name ) do |country_key, region_key|
113
+ load_breweries_for_country_n_region( country_key, region_key, name )
114
+ end
115
+ elsif match_breweries_for_country( name ) do |country_key|
116
+ load_breweries_for_country( country_key, name )
117
+ end
63
118
  else
64
119
  logger.error "unknown beer.db fixture type >#{name}<"
65
120
  # todo/fix: exit w/ error
@@ -1,4 +1,4 @@
1
1
 
2
2
  module BeerDb
3
- VERSION = '0.7.0'
3
+ VERSION = '0.7.1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beerdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &81804710 !ruby/object:Gem::Requirement
16
+ requirement: &72946910 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81804710
24
+ version_requirements: *72946910
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: worlddb
27
- requirement: &81804490 !ruby/object:Gem::Requirement
27
+ requirement: &72946690 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.7'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *81804490
35
+ version_requirements: *72946690
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: commander
38
- requirement: &81804270 !ruby/object:Gem::Requirement
38
+ requirement: &72946470 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 4.1.3
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *81804270
46
+ version_requirements: *72946470
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &81804050 !ruby/object:Gem::Requirement
49
+ requirement: &72946250 !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: *81804050
57
+ version_requirements: *72946250
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &81803830 !ruby/object:Gem::Requirement
60
+ requirement: &72946030 !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: *81803830
68
+ version_requirements: *72946030
69
69
  description: beerdb - beer.db command line tool
70
70
  email: beerdb@googlegroups.com
71
71
  executables: