lib/name_abbr.rb in name_abbr-1.0.1 vs lib/name_abbr.rb in name_abbr-1.1.0
- old
+ new
@@ -1,23 +1,28 @@
class NameAbbr
def self.abbr_name(first_name, last_name)
- if present?(last_name) && first_name.is_a?(String) && last_name.is_a?(String)
+ first_name = normalize(first_name)
+ last_name = normalize(last_name)
+
+ unless last_name.nil?
[first_name, last_name[0]].join(' ') + "."
else
first_name
end
end
def self.abbr_full_name(fullname)
- if present?(fullname) && fullname.is_a?(String) && present?(fullname.match(/ /))
+ fullname = normalize(fullname)
+
+ unless fullname.match(/ /).nil?
parts = fullname.split(' ')
[parts[0], parts[1][0]].join(' ') + "."
else
fullname
end
end
private
- def self.present?(str)
- !str.nil? && str.length > 0
+ def self.normalize(input)
+ input.to_s.strip
end
end