Class: PhoneParser
- Inherits:
-
Object
- Object
- PhoneParser
- Defined in:
- lib/ramparts/parsers/phone_parser.rb
Overview
Parses text and attempts to locate phone numbers
Instance Method Summary collapse
-
#count_phone_number_instances(text, options) ⇒ Object
Counts the number of phone number instances that occur within the block of text.
-
#find_phone_number_instances(text, options) ⇒ Object
Finds phone number instances within the block of text.
-
#replace_phone_number_instances(text, options, &block) ⇒ Object
Replaces phone number instances within the block of text with the insertable.
Instance Method Details
#count_phone_number_instances(text, options) ⇒ Object
Counts the number of phone number instances that occur within the block of text
8 9 10 11 12 13 14 15 |
# File 'lib/ramparts/parsers/phone_parser.rb', line 8 def count_phone_number_instances(text, ) raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String parsed_text = parse_phone_number(text, ) # Uses the map reduce algorithm phone_number_instances(MR_ALGO, parsed_text, ).length end |
#find_phone_number_instances(text, options) ⇒ Object
Finds phone number instances within the block of text
26 27 28 29 30 31 32 33 |
# File 'lib/ramparts/parsers/phone_parser.rb', line 26 def find_phone_number_instances(text, ) 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, ) end |
#replace_phone_number_instances(text, options, &block) ⇒ Object
Replaces phone number instances within the block of text with the insertable
18 19 20 21 22 23 |
# File 'lib/ramparts/parsers/phone_parser.rb', line 18 def replace_phone_number_instances(text, , &block) raise ArgumentError, ARGUMENT_ERROR_TEXT unless text.is_a? String instances = find_phone_number_instances(text, ) replace(text, instances.reverse!, &block) end |