module Faker::NameRU

Constants

FIRST_NAMES

First names grammar

LAST_NAMES

Last names grammar

PATRONYMICS

Patronymics grammar

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_ru.rb, line 55
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_ru.rb, line 49
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 patronymic Can be called with explicit sex (:male, :female), like:

Faker::NameRU.name(:male)

for_sex defaults to :random.

# File lib/ffakerer/name_ru.rb, line 38
def name(for_sex = :random)
  with_same_sex(for_sex) do
    case rand(2)
    when 0 then "#{last_name} #{first_name} #{patronymic}"
    else        "#{first_name} #{last_name}"
    end
  end
end
patronymic(for_sex = :random) click to toggle source

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

# File lib/ffakerer/name_ru.rb, line 61
def patronymic(for_sex = :random)
  PATRONYMICS[select_sex(for_sex)].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::NameRU.with_same_sex(:male)
  person.last_name  = Faker::NameRU.last_name
  person.first_name = Faker::NameRU.first_name
  person.patronymic = Faker::NameRU.patronymic
end

person.last_name    # => "Иванов"
person.first_name   # => "Александр"
person.patronymic   # => "Петрович"
# File lib/ffakerer/name_ru.rb, line 25
def with_same_sex(sex = :random)
  @fixed_sex = sex == :random ? GENDERS[rand(2)] : sex
  yield
ensure
  @fixed_sex = nil
end