class FTLTools::Name

Provides First and Last name based on gender and optionally culture.

Constants

CULTURES

Attributes

name[R]
to_s[R]

Public Class Methods

new(options) click to toggle source
# File lib/ftl_tools/name.rb, line 11
def initialize(options)
  @gender   = options['gender']
  @culture  = get_culture(options)
  @tdm      = DataMine.adapter_for(:text)
  @name     = new_name
end

Public Instance Methods

first_name() click to toggle source

Gender required but defaults to male.

# File lib/ftl_tools/name.rb, line 30
def first_name
  gender = if @gender == 'F'
             'female'
           else
             'male'
           end
  namefile = FTLTools.root('data/names', "#{@culture}_#{gender}_firstnames")
  @tdm.start(namefile)
  @tdm.item
end
get_culture(options) click to toggle source
# File lib/ftl_tools/name.rb, line 20
def get_culture(options)
  if options.key?('culture') && CULTURES.include?(options['culture'])
    culture = options['culture']
  else
    culture = CULTURES.sample
  end
  culture
end
last_name() click to toggle source
# File lib/ftl_tools/name.rb, line 41
def last_name
  namefile = FTLTools.root('data/names', "#{@culture}_lastnames")
  @tdm.start(namefile)
  @tdm.item
end
new_name() click to toggle source

Needs gender, produces first and last name as a single string.

# File lib/ftl_tools/name.rb, line 48
def new_name
  f_name    = first_name
  l_name    = last_name
  "#{f_name} #{l_name}"
end