class Beauvoir::Name

Attributes

female_count[RW]
male_count[RW]
name[RW]

Public Class Methods

new(name, options={}) click to toggle source
# File lib/beauvoir/name.rb, line 7
def initialize(name, options={})
  # default_options = {
  #   :significance_level => 0.95,
  # }
  @options = options #default_options.merge(options)

  @male_count = 0
  @female_count = 0
  @name = name
  # @significance_level = @options[:significance_level]
end

Public Instance Methods

guess_gender(threshold=DEFAULT_PROPORTION_THRESHOLD, lower_confidence_bound=DEFAULT_LOWER_CONFIDENCE_BOUND) click to toggle source
# File lib/beauvoir/name.rb, line 19
def guess_gender(threshold=DEFAULT_PROPORTION_THRESHOLD, lower_confidence_bound=DEFAULT_LOWER_CONFIDENCE_BOUND)
  if sufficiently_confident(threshold, lower_confidence_bound)
    gender
  else
    :unknown
  end
end
raw_female_proportion() click to toggle source
# File lib/beauvoir/name.rb, line 27
def raw_female_proportion
  return 0 unless self.total > 0
  @female_count / self.total
end
raw_male_proportion() click to toggle source
# File lib/beauvoir/name.rb, line 32
def raw_male_proportion
  return 0 unless self.total > 0
  @male_count / self.total
end
total() click to toggle source
# File lib/beauvoir/name.rb, line 37
def total
  (@male_count + @female_count).to_f
end

Private Instance Methods

female?() click to toggle source

These methods are private for a reason. You should use the guess_gender method instead. (See README.md for more discussion.)

# File lib/beauvoir/name.rb, line 45
def female?
  #pure proportions, so even the slightest greater proportion of one gender will affect this
  @female_count > @male_count
end
gender() click to toggle source
# File lib/beauvoir/name.rb, line 55
def gender
  if female?
    :female
  elsif male?
    :male
  else
    :unknown
  end
end
male?() click to toggle source
# File lib/beauvoir/name.rb, line 50
def male? 
  #pure proportions, so even the slightest greater proportion of one gender will affect this
  @male_count > @female_count
end
sufficiently_confident(threshold=DEFAULT_PROPORTION_THRESHOLD, lower_confidence_bound=DEFAULT_LOWER_CONFIDENCE_BOUND) click to toggle source
# File lib/beauvoir/name.rb, line 65
def sufficiently_confident(threshold=DEFAULT_PROPORTION_THRESHOLD, lower_confidence_bound=DEFAULT_LOWER_CONFIDENCE_BOUND)
  (raw_male_proportion > threshold || raw_female_proportion > threshold) &&
    lower > lower_confidence_bound
end