Class: DwcAgent::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/dwc_agent/parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceObject



5
6
7
# File 'lib/dwc_agent/parser.rb', line 5

def instance
  Thread.current[:dwc_agent_parser] ||= new
end

Instance Method Details

#parse(name) ⇒ Array

Parses the passed-in string and returns a list of names.

Parameters:

  • names (String)

    the name or names to be parsed

Returns:

  • (Array)

    the list of parsed names



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dwc_agent/parser.rb', line 14

def parse(name)
  return [] if name.nil? || name == ""
  cleaned = name.gsub(STRIP_OUT, ' ')
                .gsub(/[#{CHAR_SUBS.keys.join('\\')}]/, CHAR_SUBS)
                .gsub(/([A-Z]{1}\.)([[:alpha:]]{2,})/, '\1 \2')
                .gsub(COMPLEX_SEPARATORS, '\1 | \2')
                .gsub(/,\z/, '')
                .squeeze(' ').strip
  options = { 
    prefer_comma_as_separator: true,
    separator: SPLIT_BY,
    title: TITLE
  }
  namae = Namae::Parser.new(options)
  namae.parse(cleaned)
end