Class: RussianSex::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/russian_sex.rb

Instance Method Summary collapse

Constructor Details

#initializeDetector

Returns a new instance of Detector.



6
7
8
9
10
11
12
13
14
# File 'lib/russian_sex.rb', line 6

def initialize
  data_file = File.expand_path('../data/names.txt', __FILE__)

  @names = File.read(data_file).split.inject({}) do |hash, name|
    name, gender = name.split(';')
    hash[name] = gender
    hash
  end
end

Instance Method Details

#detect(name) ⇒ Object



16
17
18
# File 'lib/russian_sex.rb', line 16

def detect name
  @names[UnicodeUtils.downcase(name)] || 'undefined'
end