Class: GenderMachine::Name

Inherits:
Object
  • Object
show all
Includes:
MooseX
Defined in:
lib/gender_machine/name.rb

Constant Summary collapse

GENDER_TRANSFORM =
->(value) do
  # Ordered based roughly on frequency w/ some tweaking
  # formula: NAME_ROWS.map(&:first).each_with_object({}) { |v, obj| obj[v] ||= 0; obj[v] += 1 }
  # Following comment is part of datafile & licensed under GPLv1.2 or later
  # Syntax for "normal" name list (do not change):                                      $
  #                                                                                     $
  #    M  <male first name>                                                             $
  #    1M <male name, if first part of name;                                            $
  #            else: mostly male name>                                                  $
  #    ?M <mostly male name (= unisex name, which is mostly male)>                      $
  #                                                                                     $
  #    F  <female first name>                                                           $
  #    1F <female name, if first part of name;                                          $
  #            else: mostly female name>                                                $
  #    ?F <mostly female name (= unisex name, which is mostly female)>                  $
  #                                                                                     $
  #    ?  <unisex name (= can be male or female)>                                       $
  # Author of GenderMachine chose to map those names in order to:
  # :male
  # :probably_male
  # :possibly_male
  # :female
  # :probably_female
  # :possibly_female
  # :non_gendered
  case value
  when "F" then :female
  when "M" then :male
  when "?F" then :possibly_female
  when "?" then :non_gendered
  when "?M" then :possibly_male
  when "1F" then :probably_female
  when "1M" then :probably_male
  when "=" then nil # special case, names are equivalent
  else :unknown
  end
end
FREQUENCY_TRANSFORM =
->(value) do
  begin
    index = value.index(/[\dA-D]/)
    # end_index = index + 6
    # output = value[index..end_index].scan(/../).map do |pair|
    #   pair.hex.chr.to_i
    # end.inject(:+)
  end
end

Instance Method Summary collapse

Instance Method Details

#countryObject



69
70
71
# File 'lib/gender_machine/name.rb', line 69

def country
  COUNTRY_MAP_NUMERIC[frequency_index]
end

#frequencyObject



61
62
63
# File 'lib/gender_machine/name.rb', line 61

def frequency
  # TODO: implement
end

#frequency_indexObject



65
66
67
# File 'lib/gender_machine/name.rb', line 65

def frequency_index
  FREQUENCY_TRANSFORM.call(frequency_string)
end

#simplistic_genderObject



73
74
75
76
77
78
79
# File 'lib/gender_machine/name.rb', line 73

def simplistic_gender
  case gender.to_s
  when /female/i then :female
  when /male/i then :male
  else :non_gendered
  end
end