Module: NameGenderClassifier::DatabaseManager
- Defined in:
- lib/name_gender_classifier/database_manager.rb
Overview
Uses GDBM database to retrieve gender classification from DB_NAME.
Constant Summary collapse
- DB_NAME =
Returns the database location (which holds the classified names).
"#{Gem.loaded_specs['name_gender_classifier'].gem_dir}/lib/"\ 'name_gender_classifier/classified_names_pt-br.db'
Class Method Summary collapse
-
.find(key) ⇒ Float
Find in the database the value for a previously saved key.
-
.gdbm ⇒ GDBM?
With a block { |db| … } allow to read multiple records with a single database open request, or return the database instance for a single read request.
Class Method Details
.find(key) ⇒ Float
Find in the database the value for a previously saved key. The key holds the first name and the value the gender probability.
18 19 20 21 22 23 24 |
# File 'lib/name_gender_classifier/database_manager.rb', line 18 def self.find(key) value = gdbm[key.to_s] gdbm.close @gdbm = nil value ? value.to_f : nil end |
.gdbm ⇒ GDBM?
With a block { |db| … } allow to read multiple records with a single database open request, or return the database instance for a single read request.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/name_gender_classifier/database_manager.rb', line 31 def self.gdbm @gdbm ||= GDBM.new(DB_NAME) if block_given? yield(@gdbm) @gdbm.close @gdbm = nil else @gdbm end end |