Sha256: afd2b9281d4f1cbb886f28dcdeb1037936090e5791aace9be750bef0ade6199e

Contents?: true

Size: 790 Bytes

Versions: 2

Compression:

Stored size: 790 Bytes

Contents

class PhoneNumber < ActiveRecord::Base
  # Vcard association
  belongs_to :vcard
  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.11.1 app/models/phone_number.rb
has_vcards-0.11.0 app/models/phone_number.rb