lib/beerdb/reader.rb in beerdb-0.7.2 vs lib/beerdb/reader.rb in beerdb-0.8.0
- old
+ new
@@ -1,55 +1,12 @@
# encoding: UTF-8
module BeerDb
-#
-# rename n split TextUtils::ValueHelper into
-# WorldDb::Matcher - match_country, etc.
-# BeerDb::Matcher - match_brewery, etc.
+module Matcher
-
-## todo: move to worlddb for reuse!!! - find a better name?
-
-module FixtureMatcher
-
- def match_xxx_for_country( name, xxx, blk ) # xxx e.g. beers|breweries
- if name =~ /(?:^|\/)([a-z]{2})-[^\/]+\/#{xxx}/
- # new style: e.g. /at-austria/beers or ^at-austria!/beers
- # auto-add required country code (from folder structure)
- country_key = $1.dup
- blk.call( country_key )
- true # bingo - match found
- elsif name =~ /\/([a-z]{2})\/#{xxx}/
- # classic style: e.g. /at/beers (europe/at/beers)
- # auto-add required country code (from folder structure)
- country_key = $1.dup
- blk.call( country_key )
- true
- else
- false # no match found
- end
- end
-
- def match_xxx_for_country_n_region( name, xxx, blk ) # xxx e.g. beers|breweries
- if name =~ /(?:^|\/)([a-z]{2})-[^\/]+\/([a-z]{1,2})-[^\/]+\/#{xxx}/
- # new style: e.g. /at-austria/w-wien/beers or
- # ^at-austria!/w-wien/beers
- # nb: country must start name (^) or coming after / e.g. europe/at-austria/...
- #
- # auto-add required country n region code (from folder structure)
- country_key = $1.dup
- region_key = $2.dup
- blk.call( country_key, region_key )
- true # bingo - match found
- else
- false # no match found
- end
- end
-
-
def match_beers_for_country( name, &blk )
match_xxx_for_country( name, 'beers', blk )
end
def match_beers_for_country_n_region( name, &blk )
@@ -62,19 +19,20 @@
def match_breweries_for_country_n_region( name, &blk )
match_xxx_for_country_n_region( name, 'breweries', blk )
end
+end # module Matcher
-end # module FixtureMatcher
class Reader
include LogUtils::Logging
include BeerDb::Models
- include FixtureMatcher # see above
+ include WorldDb::Matcher
+ include BeerDb::Matcher # lets us use match_teams_for_country etc.
attr_reader :include_path
def initialize( include_path, opts = {} )