module FFaker::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/ffaker/name_cs.rb, line 63 def first_name(for_sex = :random) fetch_sample(FIRST_NAMES[select_sex(for_sex)]) 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/ffaker/name_cs.rb, line 57 def last_name(for_sex = :random) fetch_sample(LAST_NAMES[select_sex(for_sex)]) 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:
FFaker::NameCS.name(:male)
for_sex defaults to :random.
# File lib/ffaker/name_cs.rb, line 45 def name(for_sex = :random) with_same_sex(for_sex) do case rand(0..9) 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/ffaker/name_cs.rb, line 68 def prefix fetch_sample(PREFIXES) end
suffix()
click to toggle source
Generates random name suffix, an academic degree
# File lib/ffaker/name_cs.rb, line 73 def suffix fetch_sample(SUFFIXES) 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:
FFaker::NameCS.with_same_sex(:female) person.last_name = FFaker::NameCS.last_name person.first_name = FFaker::NameCS.first_name end person.last_name # => "Nováková" person.first_name # => "Jana"
# File lib/ffaker/name_cs.rb, line 32 def with_same_sex(sex = :random) @fixed_sex = sex == :random ? GENDERS[rand(0..1)] : sex yield ensure @fixed_sex = nil end