Sha256: 65598044f686e111a38a798b358a7da41707d420839822699c49b178a20c84df
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
dir = "#{File.dirname(__FILE__)}/random_data_despegar" #----dependencies-----# require "securerandom" require "#{dir}/array_randomizer" require "#{dir}/booleans" require "#{dir}/contact_info" require "#{dir}/dates" require "#{dir}/locations" require "#{dir}/names" require "#{dir}/numbers" require "#{dir}/invoice_data" require "#{dir}/id_generator" require "#{dir}/text" require "#{dir}/markov" require "#{dir}/grammar" require "#{dir}/version" class Random extend RandomDataDespegar::Booleans extend RandomDataDespegar::ContactInfo extend RandomDataDespegar::Dates extend RandomDataDespegar::Grammar extend RandomDataDespegar::Locations extend RandomDataDespegar::Names extend RandomDataDespegar::Numbers extend RandomDataDespegar::InvoiceData extend RandomDataDespegar::IdGenerator extend RandomDataDespegar::Text # 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" 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 private def self.find_path(filename) $:.each do |path| new_path = File.join(path,filename) return new_path if File.exist?(new_path) end return nil end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
random_data_despegar-2.1 | lib/random_data_despegar.rb |