Class: Faker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/faker_custom_methods.rb

Class Method Summary collapse

Class Method Details

.bell_random_in_range(from, to) ⇒ Object



21
22
23
24
# File 'lib/faker_custom_methods.rb', line 21

def bell_random_in_range( from, to )
  from, to = to, from if to < from
  ( rand * (to - from ) + rand * (to - from ) ) / 2 + from
end

.fetch_with_weighting(key) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/faker_custom_methods.rb', line 5

def fetch_with_weighting(key)
  fetched = translate("faker.#{key}")
  num = rand(fetched.length) + rand(fetched.length) - fetched.length
  fetched = fetched[num.abs] if fetched.respond_to?(:sample)
  if fetched.match(/^\//) and fetched.match(/\/$/) # A regex
    regexify(fetched)
  else
    fetched
  end
end

.random_in_range(from, to) ⇒ Object



16
17
18
19
# File 'lib/faker_custom_methods.rb', line 16

def random_in_range( from, to )
  from, to = to, from if to < from
  rand * (to - from ) + from
end