lib/nameable.rb in nameable-0.4.2 vs lib/nameable.rb in nameable-0.5.0

- old
+ new

@@ -35,12 +35,14 @@ SUFFIX_GENERATIONAL_ROMAN = /^\(*[IVX\.]+\)*$/i SUFFIX_ACADEMIC = /^(APR|RPh|MD|MA|DMD|DDS|PharmD|EngD|DPhil|JD|DD|DO|BA|BS|BSc|BE|BFA|MA|MS|MSc|MFA|MLA|MBA)$/i SUFFIX_PROFESSIONAL = /^(PE|CSA|CPA|CPL|CME|CEng|OFM|CSV|Douchebag)$/i SUFFIX_ABBREVIATION = /^[A-Z\.]+[A-Z\.]+$/ # It should be at least 2 letters - LAST_NAME_PRE_DANGLERS = /^(vere|von|van|de|del|della|di|da|pietro|vanden|du|st|la|ter|ten)$/i - LAST_NAME_PRE_CONCATS = /^(o'|o`|mc)$/i + LAST_NAME_PRE_DANGLERS = /^(mc|vere|von|van|da|de|del|della|di|da|pietro|vanden|du|st|la|ter|ten)$/i + O_LAST_NAME_PRE_CONCATS = /^(o'|o`)$/i + # MC_LAST_NAME_PRE_CONCAT = /^(mc|da|de)$/i + # ST_LAST_NAME_PRE_CONCAT = /^(st)\.*$/i end attr_accessor :prefix, :first, :middle, :last, :suffix ## @@ -83,11 +85,11 @@ end if name.join != name.join.upcase and name[n].length > 1 and name[n] =~ Patterns::SUFFIX_ABBREVIATION suff = name[n].upcase.gsub(/\./,'') end - + if suff @suffix = @suffix ? "#{suff}, #{@suffix}" : suff name.delete_at(n) end @@ -121,15 +123,19 @@ def extract_middle(name) return unless name and name.size >= 1 (name.size - 1).downto(0) do |n| next unless name[n] - + if name[n] =~ Patterns::LAST_NAME_PRE_DANGLERS - @last = "#{name[n]} #{@last}" - elsif name[n] =~ Patterns::LAST_NAME_PRE_CONCATS + @last = "#{name[n].downcase.capitalize} #{@last}" + elsif name[n] =~ Patterns::O_LAST_NAME_PRE_CONCATS @last = "O'#{@last}" + # elsif name[n] =~ Patterns::MC_LAST_NAME_PRE_CONCAT + # @last = "#{name[n].downcase.capitalize} #{@last}" + # elsif name[n] =~ Patterns::ST_LAST_NAME_PRE_CONCAT + # @last = "St. #{@last}" elsif name[n] =~ /-+/ and n > 0 and name[n-1] @last = "#{name[n-1]}-#{@last}" name[n-1] = nil else @middle = @middle ? "#{name[n]} #{@middle}" : name[n] @@ -175,20 +181,40 @@ def to_fullname to_s end + def to_prefix + @prefix + end + + def to_firstname + @first + end + + def to_lastname + @last + end + + def to_middlename + @middle + end + + def to_suffix + @suffix + end + def to_nameable [@first, @last].compact.join(' ') end - + def to_hash return { :prefix => @prefix, :first => @first, :middle => @middle, :last => @last, :suffix => @suffix } end - end + end end