Module: PicoPhone::Rails::Extraction

Extended by:
ActiveSupport::Concern
Defined in:
lib/pico_phone/rails/extraction.rb

Overview

Included into ActiveRecord::Base by the railtie. Adds an extract_phone_numbers_from class macro that wraps a free-text column with helpers for pulling out and redacting the phone numbers it mentions -- useful for notes, support tickets, and chat logs where a phone number might appear anywhere in the text, in any format.

Examples:

class Note < ApplicationRecord
  extract_phone_numbers_from :body, region: "US"
end

note.extracted_phone_numbers    # => [#<PicoPhone::PhoneNumberMatch ...>, ...]
note.body_with_phones_redacted  # => "Call me at [PHONE] or [PHONE]"

Persisting matches for cross-record search

class Note < ApplicationRecord
  extract_phone_numbers_from :body, region: "US", persist: true
end

Note.containing_phone_number("(510) 274-5656") # matches regardless of stored format