Sha256: 243140a02451ad42da4fee13ec7d7126ad78bc1c044c2e6b23dd4d058049a2c8

Contents?: true

Size: 951 Bytes

Versions: 22

Compression:

Stored size: 951 Bytes

Contents

module SportDB::Models


class League < ActiveRecord::Base
  
  ## leagues also used for conferences, world series, cups, etc.
  #
  ## league (or cup/conference/series/etc.) + season (or year) = event
  
  has_many :events
  has_many :seasons, :through => :events
  
  belongs_to :country, :class_name => 'WorldDB::Models::Country', :foreign_key => 'country_id'


  def self.create_from_ary!( leagues, more_values={} )
    leagues.each do |values|
      
      ## key & title required
      attr = {
        key:   values[0],
        title: values[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
        else
          # issue warning: unknown type for value
        end
      end

      League.create!( attr )
    end # each league
  end

end  # class League


end # module SportDB::Models

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sportdb-1.5.0 lib/sportdb/models/league.rb
sportdb-1.4.2 lib/sportdb/models/league.rb
sportdb-1.4.1 lib/sportdb/models/league.rb
sportdb-1.4.0 lib/sportdb/models/league.rb
sportdb-1.3.0 lib/sportdb/models/league.rb
sportdb-1.2.0 lib/sportdb/models/league.rb
sportdb-1.1.0 lib/sportdb/models/league.rb
sportdb-1.0.1 lib/sportdb/models/league.rb
sportdb-1.0.0 lib/sportdb/models/league.rb
sportdb-0.9.7 lib/sportdb/models/league.rb
sportdb-0.9.6 lib/sportdb/models/league.rb
sportdb-0.9.5 lib/sportdb/models/league.rb
sportdb-0.9.4 lib/sportdb/models/league.rb
sportdb-0.9.3 lib/sportdb/models/league.rb
sportdb-0.9.2 lib/sportdb/models/league.rb
sportdb-0.9.1 lib/sportdb/models/league.rb
sportdb-0.9.0 lib/sportdb/models/league.rb
sportdb-0.8.1 lib/sportdb/models/league.rb
sportdb-0.8.0 lib/sportdb/models/league.rb
sportdb-0.7.2 lib/sportdb/models/league.rb