Class: EmailParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ramparts/parsers/email_parser.rb

Overview

Parses text and attempts to locate email

Instance Method Summary collapse

Instance Method Details

#count_email_instances(text, options) ⇒ Object

Counts email occurrences within a block of text Note: Uses map reduce algorithm

Raises:

  • (ArgumentError)


10
11
12
13
14
15
# File 'lib/ramparts/parsers/email_parser.rb', line 10

def count_email_instances(text, options)
  raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String

  text = parse_email(text)
  email_instances(MR_ALGO, text, options).length
end

#find_email_instances(text, options) ⇒ Object

Fins the occurrences of emails within a block of text and returns their positions

Raises:

  • (ArgumentError)


26
27
28
29
30
31
# File 'lib/ramparts/parsers/email_parser.rb', line 26

def find_email_instances(text, options)
  raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String

  text = text.downcase
  email_instances(GR_ALGO, text, options)
end

#replace_email_instances(text, options, &block) ⇒ Object

Replaces the occurrences of email within the block of text with an insertable

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/ramparts/parsers/email_parser.rb', line 18

def replace_email_instances(text, options, &block)
  raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String

  instances = find_email_instances(text, options)
  replace(text, instances.reverse!, &block)
end