Class: BeerDb::ReaderBase
- Inherits:
-
Object
- Object
- BeerDb::ReaderBase
- Includes:
- Matcher, Models, LogUtils::Logging, WorldDb::Matcher
- Defined in:
- lib/beerdb/reader.rb
Instance Method Summary collapse
- #load(name) ⇒ Object
- #load_beers_for_country(country_key, name, more_attribs = {}) ⇒ Object
- #load_beers_for_country_n_region(country_key, region_key, name, more_attribs = {}) ⇒ Object
- #load_breweries_for_country(country_key, name, more_attribs = {}) ⇒ Object
- #load_breweries_for_country_n_region(country_key, region_key, name, more_attribs = {}) ⇒ Object
- #load_setup(name) ⇒ Object
Methods included from Matcher
#match_beers_for_country, #match_beers_for_country_n_region, #match_breweries_for_country, #match_breweries_for_country_n_region, #match_brewpubs_for_country, #match_brewpubs_for_country_n_region
Instance Method Details
#load(name) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/beerdb/reader.rb', line 56 def load( name ) if match_beers_for_country_n_region( name ) do |country_key, region_key| load_beers_for_country_n_region( country_key, region_key, name ) end elsif match_beers_for_country( name ) do |country_key| load_beers_for_country( country_key, name ) end elsif match_breweries_for_country_n_region( name ) do |country_key, region_key| load_breweries_for_country_n_region( country_key, region_key, name ) end elsif match_breweries_for_country( name ) do |country_key| load_breweries_for_country( country_key, name ) end elsif match_brewpubs_for_country_n_region( name ) do |country_key, region_key| load_breweries_for_country_n_region( country_key, region_key, name, brewpub: true ) end elsif match_brewpubs_for_country( name ) do |country_key| load_breweries_for_country( country_key, name, brewpub: true ) end else logger.error "unknown beer.db fixture type >#{name}<" # todo/fix: exit w/ error end end |
#load_beers_for_country(country_key, name, more_attribs = {}) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/beerdb/reader.rb', line 103 def load_beers_for_country( country_key, name, more_attribs={} ) country = Country.find_by_key!( country_key ) logger.debug "Country #{country.key} >#{country.title} (#{country.code})<" more_attribs[ :country_id ] = country.id more_attribs[ :txt ] = name # store source ref load_beers_worker( name, more_attribs ) end |
#load_beers_for_country_n_region(country_key, region_key, name, more_attribs = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/beerdb/reader.rb', line 83 def load_beers_for_country_n_region( country_key, region_key, name, more_attribs={} ) country = Country.find_by_key!( country_key ) logger.debug "Country #{country.key} >#{country.title} (#{country.code})<" more_attribs[ :country_id ] = country.id # NB: region lookup requires country id (region key only unique for country) region = Region.find_by_key_and_country_id( region_key, country.id ) if region.nil? # note: allow unknown region keys; issue warning n skip region logger.warn "Region w/ key >#{region_key}< not found; skip adding region" else logger.debug "Region #{region.key} >#{region.title}<" more_attribs[ :region_id ] = region.id end more_attribs[ :txt ] = name # store source ref load_beers_worker( name, more_attribs ) end |
#load_breweries_for_country(country_key, name, more_attribs = {}) ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/beerdb/reader.rb', line 136 def load_breweries_for_country( country_key, name, more_attribs={} ) country = Country.find_by_key!( country_key ) logger.debug "Country #{country.key} >#{country.title} (#{country.code})<" more_attribs[ :country_id ] = country.id more_attribs[ :txt ] = name # store source ref load_breweries_worker( name, more_attribs ) end |
#load_breweries_for_country_n_region(country_key, region_key, name, more_attribs = {}) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/beerdb/reader.rb', line 115 def load_breweries_for_country_n_region( country_key, region_key, name, more_attribs={} ) country = Country.find_by_key!( country_key ) logger.debug "Country #{country.key} >#{country.title} (#{country.code})<" more_attribs[ :country_id ] = country.id # note: region lookup requires country id (region key only unique for country) region = Region.find_by_key_and_country_id( region_key, country.id ) if region.nil? # note: allow unknown region keys; issue warning n skip region logger.warn "Region w/ key >#{region_key}< not found; skip adding region" else logger.debug "Region #{region.key} >#{region.title}<" more_attribs[ :region_id ] = region.id end more_attribs[ :txt ] = name # store source ref load_breweries_worker( name, more_attribs ) end |
#load_setup(name) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/beerdb/reader.rb', line 46 def load_setup( name ) reader = create_fixture_reader( name ) ### "virtual" method - required by concrete class reader.each do |fixture_name| load( fixture_name ) end end |