Class: NeverBounce::CLI::Script::JobsCreate::SuppliedInputParser

Inherits:
Object
  • Object
show all
Defined in:
lib/never_bounce/cli/script/jobs_create/supplied_input_parser.rb

Overview

The parser for SUPPLIED_INPUT= environment variable.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#separatorRegexp

Returns:

  • (Regexp)

16
17
18
# File 'lib/never_bounce/cli/script/jobs_create/supplied_input_parser.rb', line 16

def separator
  @separator ||= /[;,\n]/
end

Instance Method Details

#process(content) ⇒ Array<email, name> Also known as: []

Process content, return parsed structure.

NOTE: The parser doesn't validate e-mail addresses.

process("[email protected] Tom User;[email protected] Dick Other")
# => [["[email protected]", "Tom User"], ["[email protected]", "Dick Other"]]

Returns:

  • (Array<email, name>)

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/never_bounce/cli/script/jobs_create/supplied_input_parser.rb', line 30

def process(content)
  # NOTE: Keep it stage-procedural for easier debugging.
  chunks = content.split(separator).map(&:strip).reject(&:empty?)

  out = chunks.map do |chunk|
    if (chunk =~ /^(.+?)\s+(.+)$/)
      [$1, $2]
    else
      [chunk, ""]
    end
  end

  out.empty? and raise ArgumentError, "Empty content"

  out
end