Module: FFaker::NameCS

Extended by:
ModuleUtils, NameCS
Includes:
Name
Included in:
NameCS
Defined in:
lib/ffaker/name_cs.rb

Constant Summary collapse

FIRST_NAMES =
{
  female: FEMALE_FIRST_NAMES,
  male: MALE_FIRST_NAMES
}.freeze
LAST_NAMES =
{
  female: FEMALE_LAST_NAMES,
  male: MALE_LAST_NAMES
}.freeze
SUFFIXES =
%w[Ph.D. Th.D. DSc.].freeze
GENDERS =

:nodoc:

%i[male female random].freeze

Constants included from Name

FFaker::Name::FEMALE_PREFIXES, FFaker::Name::MALE_PREFIXES, FFaker::Name::OTHER_PREFIXES, FFaker::Name::PREFIXES

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, luhn_check, underscore, unique

Methods included from RandomUtils

#fetch_sample, #rand, #shuffle

Methods included from Name

#female_name_with_prefix, #female_name_with_prefix_suffix, #female_name_with_suffix, #female_prefix, #first_name_female, #first_name_male, #html_safe_last_name, #html_safe_name, #male_name_with_prefix, #male_name_with_prefix_suffix, #male_name_with_suffix, #male_prefix, #name_with_prefix, #name_with_prefix_suffix, #name_with_suffix, #other_prefix, #pronouns

Instance Method Details

#first_name(for_sex = :random) ⇒ Object

Generates random first name for_sex can be :male, :female. Defaults to :random



63
64
65
# 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) ⇒ Object

Generates random last name for_sex can be :male, :female. Defaults to :random



57
58
59
# 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) ⇒ Object

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.



45
46
47
48
49
50
51
52
53
# 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

#prefixObject

Generates random name prefix, an academic degree



68
69
70
# File 'lib/ffaker/name_cs.rb', line 68

def prefix
  fetch_sample(PREFIXES)
end

#suffixObject

Generates random name suffix, an academic degree



73
74
75
# File 'lib/ffaker/name_cs.rb', line 73

def suffix
  fetch_sample(SUFFIXES)
end

#with_same_sex(sex = :random) ⇒ Object

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"


32
33
34
35
36
37
# 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