Class: Random
- Inherits:
-
Object
- Object
- Random
- Extended by:
- RandomDataDespegar::Booleans, RandomDataDespegar::ContactInfo, RandomDataDespegar::Dates, RandomDataDespegar::Grammar, RandomDataDespegar::IdGenerator, RandomDataDespegar::InvoiceData, RandomDataDespegar::Locations, RandomDataDespegar::Names, RandomDataDespegar::Numbers, RandomDataDespegar::Text
- Defined in:
- lib/random_data_despegar.rb
Class Method Summary collapse
-
.method_missing(methodname) ⇒ Object
Looks for a file in the load path with the name methodname.dat, reads the lines from that file, then gives you a random line from that file.
Methods included from RandomDataDespegar::Booleans
Methods included from RandomDataDespegar::ContactInfo
email, international_phone, phone
Methods included from RandomDataDespegar::Dates
date, date_between, departure_and_return_dates, passenger_birthdate, passenger_birthdate_parsed
Methods included from RandomDataDespegar::Grammar
Methods included from RandomDataDespegar::Locations
address_line_1, address_line_2, cep, city, country, cpnj, state_code, state_full, uk_post_code, zipcode
Methods included from RandomDataDespegar::Names
companyname, firstname, firstname_female, firstname_male, full_name, initial, lastname
Methods included from RandomDataDespegar::Numbers
alphanumeric_with_size, bit, bits, number, number_with_size, random_card_number
Methods included from RandomDataDespegar::InvoiceData
Methods included from RandomDataDespegar::IdGenerator
Methods included from RandomDataDespegar::Text
Class Method Details
.method_missing(methodname) ⇒ Object
Looks for a file in the load path with the name methodname.dat, reads the lines from that file, then gives you a random line from that file. Raises an error if it can’t find the file. For example, given a file named “horse.dat” in your load path: >> Random.horse
> “Stallion”
>> Random.horse
> “Pony”
>> Random.horse
> “Mare”
>> Random.horse
> “Clydesdale”
>> Random.horse
> “Stallion”
>> Random.horse
> “Mare”
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/random_data_despegar.rb', line 46 def self.method_missing(methodname) thing = "#{methodname}.dat" filename = find_path(thing) if filename.nil? super else array = [] File.open(filename, 'r') { |f| array = f.read.split(/[\r\n]+/) } return array.rand end end |