Sha256: 9fdbcc416a56fe86a14152d00685dfb32fa57d05dd17896854d7cccdb6978684

Contents?: true

Size: 1.09 KB

Versions: 10

Compression:

Stored size: 1.09 KB

Contents

class User < ActiveRecord::Base
  has_many :events
  has_many :events_users
  
  def name
    "#{first_name} #{last_name}"  
  end
  
  def self.random
    find(:first, :offset => rand(count - 1))
  end
  
  def self.generate_random_data(count = 500)
    male_names = File.read("config/data/male_names.txt").split("\n")
    female_names = File.read("config/data/female_names.txt").split("\n")
    last_names = File.read("config/data/last_names.txt").split("\n")

    0.upto(count) do 
      sex = (rand(2) == 1) ? "male" : "female"
      create(:first_name => random_name(sex, male_names, female_names), :last_name => last_names[rand(last_names.size)], :sex => sex, :birthday => random_birthday)      
    end
  end

  def self.random_name(sex, male_names, female_names)
    return male_names[rand(male_names.size)] if sex == "male"
    female_names[rand(female_names.size)]
  end
  
  def self.random_birthday
    birthday = nil
    while (not birthday)
      begin
        birthday = Date.new(rand(59) + 1950, rand(12), rand(31))
      rescue 
        birthday = nil
      end
    end
    
    birthday
  end
  
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
will_filter-3.1.11 test/dummy/app/models/user.rb
will_filter-3.1.10 test/dummy/app/models/user.rb
will_filter-3.1.9 test/dummy/app/models/user.rb
will_filter-3.1.8 test/dummy/app/models/user.rb
will_filter-3.1.7 test/dummy/app/models/user.rb
will_filter-3.1.6 test/dummy/app/models/user.rb
will_filter-3.1.5 test/dummy/app/models/user.rb
will_filter-3.1.3 test/dummy/app/models/user.rb
will_filter-3.1.2 test/dummy/app/models/user.rb
will_filter-3.1.1 test/dummy/app/models/user.rb