module Hypocorism

Constants

VERSION

Public Class Methods

match(name, another) click to toggle source
# File lib/hypocorism.rb, line 18
def match(name, another)
  variations_of(name.downcase).include?(another.downcase)
end
names() click to toggle source
# File lib/hypocorism.rb, line 14
def names
  @names ||= source_with_e_varients
end
source() click to toggle source
# File lib/hypocorism.rb, line 10
def source
  File.read(source_path).lines.collect &:split
end
source_path() click to toggle source
# File lib/hypocorism.rb, line 6
def source_path
  File.expand_path('../data/nicknames.txt', File.dirname(__FILE__))
end
variations_of(name) click to toggle source
# File lib/hypocorism.rb, line 22
def variations_of(name)
  names.select{|n| n.include? name}.flatten.uniq
end

Private Class Methods

e_varients_of(string) click to toggle source
# File lib/hypocorism.rb, line 36
def e_varients_of(string)
  %w{i ie y ey}.collect{|v| string + v}
end
source_with_e_varients() click to toggle source
# File lib/hypocorism.rb, line 27
def source_with_e_varients
  source.collect! do |line|
    line.collect!{|m| /(.*)E$/ =~ m ? e_varients_of($1) : m}
    line.flatten!
    line.collect! &:downcase!
  end
end