Class: GenderMachine::Predictor

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

Constant Summary collapse

NULL_NAME =
OpenStruct.new(gender: "",
name: "",
frequency_string: "",
raw: "")

Instance Method Summary collapse

Instance Method Details

#ensure_default_response(default) ⇒ Object



13
14
15
16
# File 'lib/gender_machine/predictor.rb', line 13

def ensure_default_response(default)
  response = yield
  response || default
end

#find(name = name) ⇒ Object



18
19
20
# File 'lib/gender_machine/predictor.rb', line 18

def find(name = name)
  Core::NAMES.select(&name_match_block)
end

#first(name = name) ⇒ Object



22
23
24
25
26
# File 'lib/gender_machine/predictor.rb', line 22

def first(name = name)
  ensure_default_response(NULL_NAME) do
    Core::NAMES.detect(&name_match_block)
  end
end

#name_match_blockObject



9
10
11
# File 'lib/gender_machine/predictor.rb', line 9

def name_match_block
  ->(obj){ obj.name == name }
end

#whereObject



28
29
30
# File 'lib/gender_machine/predictor.rb', line 28

def where
  # TODO:
end