Module: SmsOnRails::ModelSupport::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#assign_carrier(carrier) ⇒ Object

Assign the carrier to the phone number if it exists carrier - can be a ActiveRecord object, a name of the carrier, or carrier id



233
234
235
236
# File 'lib/sms_on_rails/model_support/phone_number.rb', line 233

def assign_carrier(carrier)
  specified_carrier = self.class.reflections[:carrier].klass.carrier_by_value(carrier)
  self.carrier = specified_carrier if specified_carrier
end

#digitsObject Also known as: phone_number_digits



222
223
224
# File 'lib/sms_on_rails/model_support/phone_number.rb', line 222

def digits
  @digits||=self.class.digits(self.number)
end

#do_not_send?Boolean

Returns true if the number is marked as do not send (not blank) Values could be abuse, bounce, opt-out, etc

Returns:

  • (Boolean)


242
243
244
# File 'lib/sms_on_rails/model_support/phone_number.rb', line 242

def do_not_send?
  !self.do_not_send.blank?
end

#human_displayObject

The human display pretty phone number (206) 555-5555



207
208
209
# File 'lib/sms_on_rails/model_support/phone_number.rb', line 207

def human_display
  self.class.human_display(self.number)
end

#numberObject



217
218
219
220
# File 'lib/sms_on_rails/model_support/phone_number.rb', line 217

def number
  n = read_attribute :number
  n.blank? ? original_number : n
end

#number=(value) ⇒ Object



211
212
213
214
215
# File 'lib/sms_on_rails/model_support/phone_number.rb', line 211

def number=(value)
  @original_number = value unless value.blank?
  @digits = self.class.digits(value)
  write_attribute :number, @digits
end

#sms_email_addressObject

return the sms email address from the carrier



227
228
229
# File 'lib/sms_on_rails/model_support/phone_number.rb', line 227

def sms_email_address
  carrier.sms_email_address(self) if carrier
end