Sha256: ccba829f04ff51db767af9cd87a1bbbf9ed2a2e4042be111e85c0f3a90e938ac

Contents?: true

Size: 816 Bytes

Versions: 2

Compression:

Stored size: 816 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('mobile')

  def label
    case phone_number_type
    when 'phone'
      "Tel:"
    when 'fax'
      "Fax:"
    when 'mobile'
      "Mob:"
    when 'email'
      "Mail:"
    else
      ""
    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

2 entries across 2 versions & 1 rubygems

Version Path
has_vcards-0.12.1 app/models/phone_number.rb
has_vcards-0.12.0 app/models/phone_number.rb