Sha256: df56d650204d8391d52f43e69d4c5459cba203d040cab66b40b69305c207972b

Contents?: true

Size: 830 Bytes

Versions: 12

Compression:

Stored size: 830 Bytes

Contents

class PhoneNumber < ActiveRecord::Base
  # Vcard association
  belongs_to :vcard, :inverse_of => :contacts
  belongs_to :object, :polymorphic => true

  # Validation
  validates_presence_of :number

  # phone number types
  scope :by_type, lambda {|value| where(:phone_number_type => value)}
  scope :phone, by_type('phone')
  scope :fax, by_type('fax')
  scope :mobile, by_type('mobile')
  scope :email, by_type('email')

  def label
    case phone_number_type
    when 'phone'
      "Tel:"
    when 'fax'
      "Fax:"
    when 'mobile'
      "Mob:"
    when 'email'
      "Mail:"
    else
      phone_number_type
    end
  end
  
  # String
  def to_s(separator = " ", format = :default)
    case format
      when :label
        return [label, number].compact.join(separator)
      else
        return number
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
has_vcards-0.19.0 app/models/phone_number.rb
has_vcards-0.18.0 app/models/phone_number.rb
has_vcards-0.17.2 app/models/phone_number.rb
has_vcards-0.17.1 app/models/phone_number.rb
has_vcards-0.17.0 app/models/phone_number.rb
has_vcards-0.16.0 app/models/phone_number.rb
has_vcards-0.15.0 app/models/phone_number.rb
has_vcards-0.14.1 app/models/phone_number.rb
has_vcards-0.14.0 app/models/phone_number.rb
has_vcards-0.13.2 app/models/phone_number.rb
has_vcards-0.13.1 app/models/phone_number.rb
has_vcards-0.13.0 app/models/phone_number.rb