module Faker::NameCS
Constants
- FIRST_NAMES
- LAST_NAMES
- SUFFIXES
Public Instance Methods
first_name(for_sex = :random)
click to toggle source
Generates random first name for_sex can be :male, :female. Defaults to :random
# File lib/ffakerer/name_cs.rb, line 54 def first_name(for_sex = :random) FIRST_NAMES[select_sex(for_sex)].rand end
last_name(for_sex = :random)
click to toggle source
Generates random last name for_sex can be :male, :female. Defaults to :random
# File lib/ffakerer/name_cs.rb, line 48 def last_name(for_sex = :random) LAST_NAMES[select_sex(for_sex)].rand end
name(for_sex = :random)
click to toggle source
Generates random full name which can contain prefix and suffix Can be called with explicit sex (:male, :female), like:
Faker::NameCS.name(:male)
for_sex defaults to :random.
# File lib/ffakerer/name_cs.rb, line 36 def name(for_sex = :random) with_same_sex(for_sex) do case rand(10) when 0 then "#{prefix} #{first_name} #{last_name} #{suffix}" when 1..2 then "#{prefix} #{first_name} #{last_name}" else "#{first_name} #{last_name}" end end end
prefix()
click to toggle source
Generates random name prefix, an academic degree
# File lib/ffakerer/name_cs.rb, line 59 def prefix PREFIXES.rand end
suffix()
click to toggle source
Generates random name suffix, an academic degree
# File lib/ffakerer/name_cs.rb, line 64 def suffix SUFFIXES.rand end
with_same_sex(sex = :random) { || ... }
click to toggle source
All names generated inside the block will have the same sex. Can be called with explicit sex which will affect all calls inside thee block:
Faker::NameCS.with_same_sex(:female) person.last_name = Faker::NameCS.last_name person.first_name = Faker::NameCS.first_name end person.last_name # => "Nováková" person.first_name # => "Jana"
# File lib/ffakerer/name_cs.rb, line 23 def with_same_sex(sex = :random) @fixed_sex = sex == :random ? GENDERS[rand(2)] : sex yield ensure @fixed_sex = nil end