class Namie::Parser

Name parser

Constants

JURIDIC
SUFFIXES
TITLES

Attributes

first[RW]
last[RW]
middle[RW]
suffix[RW]
title[RW]
txt[RW]

Public Class Methods

new(params) click to toggle source
# File lib/namie/parser.rb, line 9
def initialize(params)
  hsh, txt = params.partition { |pm| pm.respond_to?(:key) }
  hsh.each { |k, v| send("#{k}=", v) }
  @txt = txt.map { |t| t.split(' ') }.flatten
  remove_non_names
  parse_name
  normalize
end

Public Instance Methods

args() click to toggle source
# File lib/namie/parser.rb, line 35
def args
  [title, first, middle, last, suffix]
end
normalize() click to toggle source
# File lib/namie/parser.rb, line 28
def normalize
  [:title, :middle, :suffix].each do |v|
    val =  send(v).reject(&:nil?).any? ? send(v).join(' ') : nil
    instance_variable_set("@#{v}", val)
  end
end
parse_name() click to toggle source
# File lib/namie/parser.rb, line 18
def parse_name
  @txt.push(@txt.shift.tr(',', '')) if txt.first  =~ /,/
  @first, *@middle, @last = txt.size > 2 ? txt : txt.insert(1, nil)
end
remove_non_names() click to toggle source
# File lib/namie/parser.rb, line 23
def remove_non_names
  @title, @txt = txt.partition { |a| a =~ TITLES }
  @suffix, @txt = txt.partition { |a| a =~ SUFFIXES }
end