Skip to content

Instantly share code, notes, and snippets.

@haroldus-
haroldus- / namify.rb
Last active September 2, 2019 04:43
ruby name capitalisation method with (non-exhaustive) exceptions for hyphens, apostrophes, lowercase (nobiliary) particles, and names with two capital letters
def namify(value)
array = value.split(/\b/)
array.each do |e|
next if !!e.match(/\A(-|'|’|‘|d|e|o|t|y)\Z/)
next if !!e.match(/\A(af|da|de|di|do|du|et|la|le|of|to|zu)\Z/)
next if !!e.match(/\A(das|del|den|der|des|dit|dos|lis|lix|til|und|van|von)\Z/)
next if !!e.match(/\A(Abdul|Da|De|Della|Der|Di|Du|Fitz|h|La|Ma|Mac|Mak|Mc|O|Van|Vande|Vander|Varta|Vartig)[A-Z\u00c0-\u00cf\u00d0-\u00d6\u00d8-\u00de\u0130\u0152\u0160\u0178\u017d][a-z\u00df\u00e0-\u00ef\u00f0-\u00f6\u00f8-\u00ff\u0131\u0153\u0161\u017e]+/)
e.capitalize!
end
array.join.strip