Module: Wukong::Faker::Helpers

Extended by:
Helpers
Included in:
Helpers
Defined in:
lib/wukong/model/faker.rb

Instance Method Summary collapse

Instance Method Details

#fake_area_codeObject



85
# File 'lib/wukong/model/faker.rb', line 85

def fake_area_code()        ; fake_integer(:min => 200, :max => 987) ; end

#fake_basenameObject



93
# File 'lib/wukong/model/faker.rb', line 93

def fake_basename()         ; "#{fake_identifier}.#{fake_fileext}" ; end

#fake_country_idObject

KLUDGE: uses tlds, not country codes



84
# File 'lib/wukong/model/faker.rb', line 84

def fake_country_id()       ; Forgery::Internet.cctld ; end

#fake_dirnameObject



94
# File 'lib/wukong/model/faker.rb', line 94

def fake_dirname()          ; File.join('/', * 3.times.map{ fake_identifier }) ; end

#fake_fileextObject



92
# File 'lib/wukong/model/faker.rb', line 92

def fake_fileext()          ; %w[ rb html py sh com bat doc txt pdf xml exe app].sample ; end

#fake_filenameObject



95
# File 'lib/wukong/model/faker.rb', line 95

def fake_filename()         ; File.join(fake_dirname, fake_basename) ; end

#fake_float(opts = {}) ⇒ Object



73
74
75
76
77
# File 'lib/wukong/model/faker.rb', line 73

def fake_float(opts={})
  opts = { :min => 0.0, :max => 1.0 }.merge(opts)
  min, max = [ opts[:min].to_f, opts[:max].to_f ].sort
  min + ((max-min) * Kernel.rand)
end

#fake_hostnameObject



97
# File 'lib/wukong/model/faker.rb', line 97

def fake_hostname()         ; Forgery::Internet.domain_name ; end

#fake_identifierObject



88
# File 'lib/wukong/model/faker.rb', line 88

def fake_identifier()       ; fake_word.downcase.gsub(/\W/,'_').gsub(/^[^a-z]/, 'a') ; end

#fake_integer(opts = {}) ⇒ Object



67
68
69
70
71
72
# File 'lib/wukong/model/faker.rb', line 67

def fake_integer(opts={})
  opts = { :min => 0, :max => 1 }.merge(opts)
  min, max = [ opts[:min].to_i, opts[:max].to_i ].sort
  return min if min == max
  min + Kernel.rand(max-min)
end

#fake_ip_addresssObject



98
# File 'lib/wukong/model/faker.rb', line 98

def fake_ip_addresss()      ; Forgery::Internet.ip_v4       ; end

#fake_latitude(opts = {}) ⇒ Object

A latitude unif. dist from San Diego lat 32 lng -117 to Maine lat 44 lng -68 -- sorry non-yanks



80
# File 'lib/wukong/model/faker.rb', line 80

def fake_latitude(opts={})  ; fake_float({:min =>   32.0, :max =>  45.0}.merge(opts)) ; end

#fake_longitude(opts = {}) ⇒ Object

A longitude unif. dist from San Diego lat 32 lng -117 to Maine lat 44 lng -68 -- sorry non-yanks



82
# File 'lib/wukong/model/faker.rb', line 82

def fake_longitude(opts={}) ; fake_float({:min => -117.0, :max => -68.0}.merge(opts)) ; end

#fake_paragraphObject



90
# File 'lib/wukong/model/faker.rb', line 90

def fake_paragraph()        ; Forgery::LoremIpsum.paragraph(:random => true) ; end

#fake_sentenceObject



89
# File 'lib/wukong/model/faker.rb', line 89

def fake_sentence()         ; Forgery::LoremIpsum.sentence(:random => true) ; end

#fake_version_numberObject



99
# File 'lib/wukong/model/faker.rb', line 99

def fake_version_number()   ; "%.1f" % fake_float(:min => 0.2, :max => 9.4) ; end

#fake_wordObject



87
# File 'lib/wukong/model/faker.rb', line 87

def fake_word()             ; Forgery::LoremIpsum.word(:random => true) ; end