readded "junk removal" from usernames before output

This commit is contained in:
Christian Mehlmauer
2013-05-28 19:45:20 +02:00
parent 8c9d82cb6d
commit fd7017f530
4 changed files with 174 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ class WpUsers < WpItems
headings = ['Id', 'Login', 'Name']
headings << 'Password' if options[:show_password]
remove_junk_from_display_names
self.each do |wp_user|
row = [wp_user.id, wp_user.login, wp_user.display_name]
row << wp_user.password if options[:show_password]
@@ -25,5 +27,21 @@ class WpUsers < WpItems
puts table
end
def remove_junk_from_display_names
display_names = []
self.each do |u|
display_name = u.display_name
unless display_name == 'empty'
display_names << display_name
end
end
junk = get_equal_string_end(display_names)
unless junk.nil? or junk.empty?
self.each do |u|
u.display_name = u.display_name.sub(/#{Regexp.escape(junk)}$/, '')
end
end
end
end
end

View File

@@ -112,3 +112,28 @@ def redefine_constant(constant, value)
Object.send(:remove_const, constant)
Object.const_set(constant, value)
end
# Gets the string all elements in stringarray ends with
def get_equal_string_end(stringarray = [''])
already_found = ''
looping = true
counter = -1
if stringarray.kind_of? Array and stringarray.length > 1
base = stringarray[0]
while looping
character = base[counter, 1]
stringarray.each do |s|
if s[counter, 1] != character
looping = false
break
end
end
if looping == false or (counter * -1) > base.length
break
end
already_found = "#{character if character}#{already_found}"
counter -= 1
end
end
already_found
end