Sha256: 25970161522df3631e315371016cd729ce2387aa58dd3b17f21a667b9e76e24b

Contents?: true

Size: 951 Bytes

Versions: 7

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

7 entries across 7 versions & 1 rubygems

Version Path
sportdb-1.6.6 lib/sportdb/models/league.rb
sportdb-1.6.5 lib/sportdb/models/league.rb
sportdb-1.6.4 lib/sportdb/models/league.rb
sportdb-1.6.3 lib/sportdb/models/league.rb
sportdb-1.6.2 lib/sportdb/models/league.rb
sportdb-1.6.1 lib/sportdb/models/league.rb
sportdb-1.6.0 lib/sportdb/models/league.rb