Class: EmailParser
- Inherits:
-
Object
- Object
- EmailParser
- Defined in:
- lib/ramparts/parsers/email_parser.rb
Overview
Parses text and attempts to locate email
Instance Method Summary collapse
-
#count_email_instances(text, options) ⇒ Object
Counts email occurrences within a block of text Note: Uses map reduce algorithm.
-
#find_email_instances(text, options) ⇒ Object
Fins the occurrences of emails within a block of text and returns their positions.
-
#replace_email_instances(text, options, &block) ⇒ Object
Replaces the occurrences of email within the block of text with an insertable.
Instance Method Details
#count_email_instances(text, options) ⇒ Object
Counts email occurrences within a block of text Note: Uses map reduce algorithm
10 11 12 13 14 15 |
# File 'lib/ramparts/parsers/email_parser.rb', line 10 def count_email_instances(text, ) raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String text = parse_email(text) email_instances(MR_ALGO, text, ).length end |
#find_email_instances(text, options) ⇒ Object
Fins the occurrences of emails within a block of text and returns their positions
26 27 28 29 30 31 |
# File 'lib/ramparts/parsers/email_parser.rb', line 26 def find_email_instances(text, ) raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String text = text.downcase email_instances(GR_ALGO, text, ) end |
#replace_email_instances(text, options, &block) ⇒ Object
Replaces the occurrences of email within the block of text with an insertable
18 19 20 21 22 23 |
# File 'lib/ramparts/parsers/email_parser.rb', line 18 def replace_email_instances(text, , &block) raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String instances = find_email_instances(text, ) replace(text, instances.reverse!, &block) end |