Class: Gimei

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gimei.rb,
lib/gimei/config.rb,
lib/gimei/version.rb,
lib/gimei/unique_generator.rb

Defined Under Namespace

Classes: Address, Config, Name, RetryLimitExceeded, UniqueGenerator

Constant Summary collapse

GENDERS =

: [:male, :female]

[:male, :female].freeze
VERSION =
"1.5.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gender = nil) ⇒ Gimei

Returns a new instance of Gimei.



79
80
81
82
# File 'lib/gimei.rb', line 79

def initialize(gender = nil)
  @name = Name.new(gender)
  @address = Address.new
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



22
23
24
# File 'lib/gimei.rb', line 22

def address
  @address
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/gimei.rb', line 22

def name
  @name
end

Class Method Details

.addressObject



50
51
52
# File 'lib/gimei.rb', line 50

def address
  Address.new
end

.addressesObject



38
39
40
# File 'lib/gimei.rb', line 38

def addresses
  @addresses ||= YAML.load_file(File.expand_path(File.join('..', 'data', 'addresses.yml'), __FILE__))
end

.configObject



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

def config
  @config ||= Config.new
end

.name(gender = nil) ⇒ Object



30
31
32
# File 'lib/gimei.rb', line 30

def name(gender = nil)
  Name.new(gender)
end

.namesObject



34
35
36
# File 'lib/gimei.rb', line 34

def names
  @names ||= YAML.load_file(File.expand_path(File.join('..', 'data', 'names.yml'), __FILE__))
end

.unique(max_retries = 10_000) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/gimei.rb', line 54

def unique(max_retries = 10_000)
  return @unique if defined? @unique

  @unique = UniqueGenerator.new(self, max_retries)

  %i[name last first hiragana katakana romaji address prefecture city town].each do |method_name|
    @unique.define_unique_method(method_name)
  end

  @unique.define_unique_method(:family, :last)
  @unique.define_unique_method(:given, :first)

  %i[male female kanji].each do |method_name|
    @unique.define_unique_method(method_name, :name)
  end

  @unique
end