Class: PhoneParser

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

Overview

Parses text and attempts to locate phone numbers

Instance Method Summary collapse

Instance Method Details

#count_phone_number_instances(text, options) ⇒ Object

Counts the number of phone number instances that occur within the block of text

Raises:

  • (ArgumentError)


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

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

  parsed_text = parse_phone_number(text, options)

  # Uses the map reduce algorithm
  phone_number_instances(MR_ALGO, parsed_text, options).length
end

#find_phone_number_instances(text, options) ⇒ Object

Finds phone number instances within the block of text

Raises:

  • (ArgumentError)


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

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

  text = text.downcase

  # Finds the phone number instances using the glorified regex algorithm
  phone_number_instances(GR_ALGO, text, options)
end

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

Replaces phone number instances within the block of text with the insertable

Raises:

  • (ArgumentError)


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

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

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