class Faker::Types
def character
-
(String)
-
def character sample(CHARACTERS) end
def complex_rb_hash(number: 1)
-
(Hash)
-
Parameters:
-
number
(Integer
) -- Specifies the number of key-value pairs.
def complex_rb_hash(number: 1) rb_hash(number: number, type: -> { random_complex_type }) end
def random_complex_type
-
(String, Integer)
-
def random_complex_type types = SIMPLE_TYPES + COMPLEX_TYPES type_to_use = types[rand(0..types.length - 1)] case type_to_use when :string rb_string when :fixnum rb_integer when :hash rb_hash when :array rb_array end end
def random_type
-
(String, Integer)
-
def random_type type_to_use = SIMPLE_TYPES[rand(0..SIMPLE_TYPES.length - 1)] case type_to_use when :string rb_string when :fixnum rb_integer end end
def rb_array(len: 1)
-
(Array)
-
Parameters:
-
len
(Integer
) -- Specifies the number of elements in the array.
def rb_array(len: 1) [].tap do |ar| len.times do ar.push random_type end end end
def rb_hash(number: 1, type: -> { random_type })
-
(Hash)
-
Parameters:
-
number
(Integer
) -- Specifies the number of key-value pairs.
def rb_hash(number: 1, type: -> { random_type }) {}.tap do |hsh| Lorem.words(number: number * 2).uniq.first(number).each do |s| value = type.is_a?(Proc) ? type.call : type hsh.merge!(s.to_sym => value) end end end
def rb_integer(from: 0, to: 100)
-
(Integer)
-
def rb_integer(from: 0, to: 100) rand(from..to).to_i end
def rb_string(words: 1)
-
(String)
-
def rb_string(words: 1) resolved_num = resolve(words) word_list = translate('faker.lorem.words') word_list *= ((resolved_num / word_list.length) + 1) shuffle(word_list)[0, resolved_num].join(' ') end
def titleize(word)
def titleize(word) word.split(/(\W)/).map(&:capitalize).join end