Class: RussianSex::Detector
- Inherits:
-
Object
- Object
- RussianSex::Detector
- Defined in:
- lib/russian_sex.rb
Instance Method Summary collapse
- #detect(name) ⇒ Object
-
#initialize ⇒ Detector
constructor
A new instance of Detector.
Constructor Details
#initialize ⇒ Detector
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.('../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 |