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-models-1.12.0 lib/sportdb/models/team_compat.rb
sportdb-models-1.11.2 lib/sportdb/models/team_compat.rb
sportdb-models-1.11.1 lib/sportdb/models/team_compat.rb
sportdb-models-1.11.0 lib/sportdb/models/team_compat.rb
sportdb-models-1.10.1 lib/sportdb/models/team_comp.rb
sportdb-models-1.10.0 lib/sportdb/models/team_comp.rb
sportdb-1.9.16 lib/sportdb/models/team_comp.rb
sportdb-1.9.15 lib/sportdb/models/team_comp.rb
sportdb-1.9.14 lib/sportdb/models/team_comp.rb
sportdb-1.9.13 lib/sportdb/models/team_comp.rb
sportdb-1.9.12 lib/sportdb/models/team_comp.rb
sportdb-1.9.11 lib/sportdb/models/team_comp.rb
sportdb-1.9.10 lib/sportdb/models/team_comp.rb
sportdb-1.9.9 lib/sportdb/models/team_comp.rb
sportdb-1.9.8 lib/sportdb/models/team_comp.rb
sportdb-1.9.7 lib/sportdb/models/team_comp.rb
sportdb-1.9.6 lib/sportdb/models/team_comp.rb
sportdb-1.9.5 lib/sportdb/models/team_comp.rb
sportdb-1.9.4 lib/sportdb/models/team_comp.rb
sportdb-1.9.3 lib/sportdb/models/team_comp.rb