lib/beerdb/reader.rb in beerdb-0.6.15 vs lib/beerdb/reader.rb in beerdb-0.7.0
- old
+ new
@@ -64,37 +64,28 @@
logger.error "unknown beer.db fixture type >#{name}<"
# todo/fix: exit w/ error
end
end
+
def load_brewery_wikipedia( lang_key, name )
- path = "#{include_path}/#{name}.yml"
+ reader = HashReaderV2.new( name, include_path )
- logger.info "parsing data '#{name}' (#{path})..."
-
- reader = HashReader.new( path )
-
reader.each do |key, value|
brewery = Brewery.find_by_key!( key )
wikipedia = "#{lang_key}.wikipedia.org/wiki/#{value.strip}"
logger.debug " adding #{key} => >#{wikipedia}<"
brewery.wikipedia = wikipedia
brewery.save!
end
-
- Prop.create_from_fixture!( name, path )
end
def load_brewery_prod( name )
- path = "#{include_path}/#{name}.yml"
+ reader = HashReaderV2.new( name, include_path )
- logger.info "parsing data '#{name}' (#{path})..."
-
- reader = HashReader.new( path )
-
reader.each do |key, value|
brewery = Brewery.find_by_key!( key )
if value =~ /(?:([0-9][0-9_ ]+[0-9]|[0-9]{1,2})\s*hl)/ # e.g. 20_0000 hl or 50hl etc.
prod = $1.gsub(/[ _]/, '').to_i
@@ -103,94 +94,80 @@
brewery.save!
else
logger.warn " unknown type for brewery prod value >#{value}<; regex pattern match failed"
end
end
-
- Prop.create_from_fixture!( name, path )
end
- def load_beers_for_country_n_region( country_key, region_key, name, more_values={} )
+ 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})<"
# NB: region lookup requires country id (region key only unique for country)
region = Region.find_by_key_and_country_id!( region_key, country.id )
logger.debug "Region #{region.key} >#{region.title}<"
- more_values[ :country_id ] = country.id
- more_values[ :region_id ] = region.id
+ more_attribs[ :country_id ] = country.id
+ more_attribs[ :region_id ] = region.id
- more_values[ :txt ] = name # store source ref
+ more_attribs[ :txt ] = name # store source ref
- load_beers_worker( name, more_values )
+ load_beers_worker( name, more_attribs )
end
- def load_beers_for_country( country_key, name, more_values={} )
+ 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_values[ :country_id ] = country.id
+ more_attribs[ :country_id ] = country.id
- more_values[ :txt ] = name # store source ref
+ more_attribs[ :txt ] = name # store source ref
- load_beers_worker( name, more_values )
+ load_beers_worker( name, more_attribs )
end
- def load_beers_worker( name, more_values={} )
- path = "#{include_path}/#{name}.txt"
+ def load_beers_worker( name, more_attribs={} )
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
- logger.info "parsing data '#{name}' (#{path})..."
-
- reader = ValuesReader.new( path, more_values )
-
reader.each_line do |new_attributes, values|
- Beer.create_or_update_from_values( new_attributes, values )
+ Beer.create_or_update_from_attribs( new_attributes, values )
end # each_line
-
- Prop.create_from_fixture!( name, path )
end
- def load_breweries_for_country_n_region( country_key, region_key, name, more_values={} )
+ 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})<"
# NB: region lookup requires country id (region key only unique for country)
region = Region.find_by_key_and_country_id!( region_key, country.id )
logger.debug "Region #{region.key} >#{region.title}<"
- more_values[ :country_id ] = country.id
- more_values[ :region_id ] = region.id
+ more_attribs[ :country_id ] = country.id
+ more_attribs[ :region_id ] = region.id
- more_values[ :txt ] = name # store source ref
+ more_attribs[ :txt ] = name # store source ref
- load_breweries_worker( name, more_values )
+ load_breweries_worker( name, more_attribs )
end
- def load_breweries_for_country( country_key, name, more_values={} )
+ 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_values[ :country_id ] = country.id
+ more_attribs[ :country_id ] = country.id
- more_values[ :txt ] = name # store source ref
+ more_attribs[ :txt ] = name # store source ref
- load_breweries_worker( name, more_values )
+ load_breweries_worker( name, more_attribs )
end
- def load_breweries_worker( name, more_values={} )
- path = "#{include_path}/#{name}.txt"
+ def load_breweries_worker( name, more_attribs={} )
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
- logger.info "parsing data '#{name}' (#{path})..."
-
- reader = ValuesReader.new( path, more_values )
-
reader.each_line do |new_attributes, values|
- Brewery.create_or_update_from_values( new_attributes, values )
+ Brewery.create_or_update_from_attribs( new_attributes, values )
end # each_line
-
- Prop.create_from_fixture!( name, path )
end
end # class Reader
end # module BeerDb