lib/namor/namor.rb in namor-0.5.2 vs lib/namor/namor.rb in namor-0.5.3
- old
+ new
@@ -36,10 +36,16 @@
def fullscrub(name, opts = {})
final_cleaning(scrub(name, opts))
end
+ # scrub as above, but as a final stage, convert the result to a single term (no spaces or hyphens between bits)
+ def scrub_and_squash(name, opts = {})
+ s = scrub(name, opts)
+ s && s.gsub(/[- ]/, '')
+ end
+
def demaiden(lastname)
return [nil,nil] unless lastname && !lastname.empty?
if lastname =~ /\-/
[lastname.upcase.gsub(/ /, ''), lastname.split(/\-/).last.gsub(/ /, '')]
else
@@ -110,21 +116,16 @@
def extract_from_pieces(hash)
assemble(
scrub(hash[:first]),
scrub(hash[:middle]),
- scrub(hash[:last].upcase),
- scrub(demaiden(hash[:last].upcase).last)
+ scrub_and_squash(hash[:last].upcase),
+ scrub_and_squash(demaiden(hash[:last].upcase).last)
)
end
def extract_from_pieces_with_cluster(hash)
- ary = assemble(
- scrub(hash[:first]),
- scrub(hash[:middle]),
- scrub(hash[:last]),
- scrub(demaiden(hash[:last]).last)
- )
+ ary = extract_from_pieces(hash)
ary << ary[3].gsub(/\W/, '_')
ary << ary[4].gsub(/\W/, '_')
end
def components(*args)