Skip to content

Commit

Permalink
add more attribs to ground n team
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Feb 14, 2014
1 parent d57109d commit aafb7dd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 12 deletions.
19 changes: 12 additions & 7 deletions lib/sportdb/models/ground.rb
Expand Up @@ -19,20 +19,23 @@ def self.create_or_update_from_values( new_attributes, values )
city_title = ''

values.each_with_index do |value, index|
if value =~ /^[12][0-9]{3}$/ ## assume founding year
# skip founding/opening year fow now
logger.info " found year #{value}; skipping for now"
if value =~ /^(19|20)[0-9]{2}$/ ## assume founding year -- allow 19|20
logger.info " founding/opening year #{value}"
new_attributes[ :since ] = value.to_i
elsif value =~ /^[1-9][0-9_]+[0-9]$/ # number; assume capacity e.g. 12_541 or similar
# todo/fix: check how to differentiate between founding year and capacity if capcity islike year
# todo/fix: check how to differentiate between founding year
# and capacity if capcity islike year
# need to use _ e.g. 1_999 not 1999 and will get added as capacity !!!
# - by position ?? year is first entry, capacity is second ??? -add/fix

# skip capacity
logger.info " found capacity #{value}; skipping for now"
logger.info " found capacity #{value}"
new_attributes[ :capacity ] = value.gsub('_', '').to_i
elsif value =~ /^[A-Z]{1,3}$/ # assume; state/region code e-g B | TX etc.
# skip region/state code
logger.info " found region/state code #{value}; skipping for now"
elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
logger.info " found address line #{value}; skipping for now"
logger.info " found address line #{value}"
new_attributes[ :address ] = value
elsif value =~ /^clubs:/ # assume it's clubs line e.g. clubs: Santos
logger.info " found clubs line #{value}; skipping for now"
elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
Expand Down Expand Up @@ -67,6 +70,8 @@ def self.create_or_update_from_values( new_attributes, values )
#### try to auto-add city

if city_title.present?

### todo/fix: strip city_title subtitles e.g. Hamburg (Hafen) becomes Hamburg etc.
city_values = [city_title]
city_attributes = {
country_id: rec.country_id,
Expand Down
11 changes: 11 additions & 0 deletions lib/sportdb/models/team.rb
Expand Up @@ -54,9 +54,20 @@ def self.create_or_update_from_values( new_attributes, values )
logger.warn "city with key #{value_city_key} missing"
## todo: log errors to db log???
end
elsif value =~ /^(18|19|20)[0-9]{2}$/ ## assume founding year -- allow 18|19|20
## logger.info " founding/opening year #{value}"
new_attributes[ :since ] = value.to_i
elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
## logger.info " found address line #{value}"
new_attributes[ :address ] = value
elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
logger.info " found wikipedia line #{value}; skipping for now"
elsif value =~ /(^www\.)|(\.com$)/ # FIX: !!!! use a better matcher not just www. and .com
new_attributes[ :web ] = value
elsif value =~ /^[A-Z][A-Z0-9][A-Z0-9_]?$/ ## assume two or three-letter code e.g. FCB, RBS, etc.
new_attributes[ :code ] = value
elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
## fix: allow country letter with three e.g. eng,sco,wal,nir, etc. !!!
value_country = Country.find_by_key!( value )
new_attributes[ :country_id ] = value_country.id
else
Expand Down
10 changes: 6 additions & 4 deletions lib/sportdb/reader.rb
Expand Up @@ -107,9 +107,10 @@ def load( name ) # convenience helper for all-in-one reader
load_leagues( name, club: true, country_id: country.id )
end
elsif name =~ /(?:^|\/)leagues/ # NB: ^leagues or also possible world!/leagues - NB: make sure goes after leagues_for_country!!
if name =~ /-cup!?\// # NB: -cup/ or -cup!/
if name =~ /-cup!?\// || # NB: -cup/ or -cup!/
name =~ /copa-america!?\// # NB: copa-america/ or copa-america!/
# e.g. national team tournaments/leagues (e.g. world-cup/ or euro-cup/)
load_leagues( name )
load_leagues( name, club: false )
else
# e.g. leagues_club
load_leagues( name, club: true )
Expand All @@ -121,10 +122,11 @@ def load( name ) # convenience helper for all-in-one reader
load_teams( name, club: true, country_id: country.id )
end
elsif name =~ /(?:^|\/)teams/
if name =~ /-cup!?\// # NB: -cup/ or -cup!/
if name =~ /-cup!?\// || # NB: -cup/ or -cup!/
name =~ /copa-america!?\// # NB: copa-america/ or copa-america!/
# assume national teams
# e.g. world-cup/teams amercia-cup/teams_northern
load_teams( name, national: true )
load_teams( name, club: false )
else
# club teams (many countries)
# e.g. club/europe/teams
Expand Down
9 changes: 9 additions & 0 deletions lib/sportdb/schema.rb
Expand Up @@ -15,6 +15,10 @@ def up
t.references :city # NB: city is optional (should be required for clubs e.g. non-national teams)
t.boolean :club, null: false, default: false # is it a club (not a national team)?

t.integer :since # founding year
t.string :address
t.string :web

### fix: remove and add virtual attribute in model instead
t.boolean :national, null: false, default: false # is it a national selection team (not a club)?
t.timestamps
Expand All @@ -31,6 +35,11 @@ def up
t.references :country, null: false
t.references :city # todo: make city required ???

t.integer :since # founding year
t.integer :capacity # attentence capacity e.g. 10_000 or 50_000 etc.
t.string :address


### fix/todo: add since/founded/opened/build attrib eg. 2011 or 1987
## - add capacity e.g. 40_000
## fix: add address !!!! etc
Expand Down
2 changes: 1 addition & 1 deletion lib/sportdb/version.rb
@@ -1,6 +1,6 @@

module SportDb
VERSION = '1.8.2'
VERSION = '1.8.3'
end


Expand Down

0 comments on commit aafb7dd

Please sign in to comment.