Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: generate attributes by fixed RNG #34

Merged
merged 2 commits into from
Mar 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/gimei.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def name
def address
Address.new
end

def config
@_config ||= Config.new
end
end

class Config
attr_accessor :rng

def initialize
@rng = Random.new
end
end

def initialize(gender = nil)
Expand Down
6 changes: 3 additions & 3 deletions lib/gimei/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def romaji
end

def initialize
@prefectures = Gimei::ADDRESSES['addresses']['prefecture'].sample
@prefectures = Gimei::ADDRESSES['addresses']['prefecture'].sample(random: Gimei.config.rng)
end

alias_method :to_s, :kanji
Expand All @@ -67,7 +67,7 @@ def romaji
end

def initialize
@cities = Gimei::ADDRESSES['addresses']['city'].sample
@cities = Gimei::ADDRESSES['addresses']['city'].sample(random: Gimei.config.rng)
end

alias_method :to_s, :kanji
Expand All @@ -91,7 +91,7 @@ def romaji
end

def initialize
@towns = Gimei::ADDRESSES['addresses']['town'].sample
@towns = Gimei::ADDRESSES['addresses']['town'].sample(random: Gimei.config.rng)
end

alias_method :to_s, :kanji
Expand Down
8 changes: 4 additions & 4 deletions lib/gimei/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def female
end

def initialize(gender = nil)
@gender = gender || Gimei::GENDERS.sample
@gender = gender || Gimei::GENDERS.sample(random: Gimei.config.rng)
@first = First.new @gender
@last = Last.new
end
Expand Down Expand Up @@ -63,8 +63,8 @@ def female
def_delegators :@name, :kanji, :hiragana, :katakana, :to_s, :romaji

def initialize(gender = nil)
@gender = gender || Gimei::GENDERS.sample
@name = NameWord.new(Gimei::NAMES['first_name'][@gender.to_s].sample)
@gender = gender || Gimei::GENDERS.sample(random: Gimei.config.rng)
@name = NameWord.new(Gimei::NAMES['first_name'][@gender.to_s].sample(random: Gimei.config.rng))
end

def male?
Expand All @@ -81,7 +81,7 @@ class Last
def_delegators :@name, :kanji, :hiragana, :katakana, :to_s, :romaji

def initialize
@name = NameWord.new(Gimei::NAMES['last_name'].sample)
@name = NameWord.new(Gimei::NAMES['last_name'].sample(random: Gimei.config.rng))
end
end

Expand Down