Sha256: 7b8ad1c99eaa91dc632e971156f8677ca53eea26921fb914a4f86efd0e66785b
Contents?: true
Size: 1.64 KB
Versions: 44
Compression:
Stored size: 1.64 KB
Contents
# encoding: utf-8 module SportDb module Model ############################################################# # collect depreciated or methods for future removal here # - keep for now for compatibility (for old code) class Team def self.create_from_ary!( teams, more_values={} ) teams.each do |values| ## key & title required attr = { key: values[0] } ## title (split of optional synonyms) # e.g. FC Bayern Muenchen|Bayern Muenchen|Bayern titles = values[1].split('|') attr[ :title ] = titles[0] ## add optional synonyms attr[ :synonyms ] = titles[1..-1].join('|') if titles.size > 1 attr = attr.merge( more_values ) ## check for optional values values[2..-1].each do |value| if value.is_a? Country attr[ :country_id ] = value.id elsif value.is_a? City attr[ :city_id ] = value.id elsif value =~ /#{TEAM_CODE_PATTERN}/ ## assume its three letter code (e.g. ITA or S04 etc.) attr[ :code ] = value elsif value =~ /^city:/ ## city: value_city_key = value[5..-1] ## cut off city: prefix value_city = City.find_by_key!( value_city_key ) attr[ :city_id ] = value_city.id else attr[ :title2 ] = value end end ## check if exists team = Team.find_by_key( values[0] ) if team.present? puts "*** warning team with key '#{values[0]}' exists; skipping create" else Team.create!( attr ) end end # each team end end # class Team end # module Model end # module SportDb
Version data entries
44 entries across 44 versions & 2 rubygems
Version | Path |
---|---|
sportdb-1.9.2 | lib/sportdb/models/team_comp.rb |
sportdb-1.9.1 | lib/sportdb/models/team_comp.rb |
sportdb-1.9.0 | lib/sportdb/models/team_comp.rb |
sportdb-1.8.29 | lib/sportdb/models/team_comp.rb |