Class: Raev::Author

Inherits:
Object
  • Object
show all
Defined in:
lib/raev/author.rb

Class Method Summary collapse

Class Method Details

.normalize_name(author_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/raev/author.rb', line 5

def self.normalize_name author_name
  if author_name.nil?
    return nil
  else
    # Strip whitespace
    author = author_name.strip
    if author.empty?
      return nil
    end
    
    # Ignore common strings that are not names of people
    no_authors = ["admin", "blogs", "editor", "staff"]
    
    if no_authors.include?(author.downcase)
      return nil
    end
  end
        
  # Parse notation "[email protected] (Andreas)"
  m = /\((.*)\)/.match(author)
  unless m.nil?
    author = m[1]
  end

  # Remove nickname quotes
  author = author.gsub(/\"(.*)\"/, "").gsub(/\'(.*)\'/, "").gsub("  ", " ")

			# Remove "by"
			author = author.gsub("by ", "")

  # Capitalize
  return author.split(' ').map(&:capitalize).join(' ')
end