Class: Raev::Author

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

Constant Summary collapse

NO_AUTHOR_STRINGS =
[
  "admin".freeze,
  "blogs".freeze,
  "editor".freeze,
  "staff".freeze
]
REGEX_EMAIL_WITH_NAME =
/\((.*)\)/
REGEX_QUOTES =
/\'(.*)\'/
REGEX_DOUBLE_QUOTES =
/\"(.*)\"/

Class Method Summary collapse

Class Method Details

.normalize_name(author_name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/raev/author.rb', line 16

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        
    if NO_AUTHOR_STRINGS.include?(author.downcase)
      return nil
    end
  end
        
  # Parse notation "[email protected] (Andreas)"
  m = REGEX_EMAIL_WITH_NAME.match(author)
  unless m.nil?
    author = m[1]
  end
  
  # Remove nickname quotes
  author.gsub!(REGEX_DOUBLE_QUOTES, "".freeze)
  author.gsub!(REGEX_QUOTES, "".freeze)
  author.gsub!("  ".freeze, " ".freeze)

      # Remove "by"
      author.gsub!("by ".freeze, "".freeze)

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