Module: SmsOnRails::ModelSupport::PhoneCarrier::ClassMethods

Defined in:
lib/sms_on_rails/model_support/phone_carrier.rb

Instance Method Summary collapse

Instance Method Details

#carrier_by_value(carrier) ⇒ Object

Retrurns the SmsOnRails::PhoneCarrier object carrier can be

  • symbol name of the object (ex :verizon)

  • text name (Ex. ‘Verizon’)

  • SmsOnRails::PhoneCarrier instance returns self

  • the id number



30
31
32
33
34
35
36
37
# File 'lib/sms_on_rails/model_support/phone_carrier.rb', line 30

def carrier_by_value(carrier)
  phone_carrier = case carrier.class.to_s
    when 'Symbol', 'String'   then find_by_name(carrier)
    when "#{self.class.to_s}" then carrier
    when 'Fixnum'             then find_by_id(carrier)
    else nil
  end
end

#carrier_from_sms_email(address) ⇒ Object

Return the number text and carrier obj from an email string carrier_from_sms_email ‘[email protected] ’ => [12065551234, <SmsOnRails::PhoneCarrier>]



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sms_on_rails/model_support/phone_carrier.rb', line 41

def carrier_from_sms_email(address)

  number = address
  carrier = nil

  if address.match(/^\s*(\d+)@(\S+)\s*$/)
    number = match[1]
    carrier_name = match[2]
    carrier = find_by_email_domain(match[2]) if match[2]
  end
  
  [number, carrier]
end

#sms_email_address(phone, carrier) ⇒ Object

Returns the email address for sms

  • phone - phone number digits or an SmsOnRails::PhoneCarrier

  • carrier - the name, instance, or id of a carrier

SmsOnRails::PhoneCarrier.sms_email_address('12065551111', 1) => '[email protected]'


18
19
20
21
22
# File 'lib/sms_on_rails/model_support/phone_carrier.rb', line 18

def sms_email_address(phone, carrier)
  phone_carrier = carrier_by_value(carrier)
  raise SmsOnRails::SmsError("Invalid carrier: #{carrier}") unless phone_carrier
  phone_carrier.sms_email_address(phone)
end