Sha256: ccf0c7f8d5d1f2c5f6b81aa05d421156a859b95fc2d69b4a501a61a4b81fa8ed

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

class Address < ActiveRecord::Base
  # Access restrictions
  attr_accessible :extended_address, :street_address, :post_office_box, :postal_code, :locality, :zip_locality

  belongs_to :vcard

  # Validations
  include I18nHelpers

  def validate_address
    errors.add_on_blank(:postal_code)
    errors.add_on_blank(:locality)

    if street_address.blank? and extended_address.blank? and post_office_box.blank?
      errors.add(:street_address, "#{t_attr(:street_address, Vcard)} #{I18n.translate('errors.messages.empty')}")
      errors.add(:extended_address, "#{t_attr(:extended_address, Vcard)} #{I18n.translate('errors.messages.empty')}")
      errors.add(:post_office_box, "#{t_attr(:post_office_box, Vcard)} #{I18n.translate('errors.messages.empty')}")
    end
  end

  # Helpers
  def to_s
    I18n.translate('has_vcards.address.to_s',
      :street_address => street_address,
      :postal_code => postal_code,
      :locality => locality
    )
  end

  # Composed attributes
  def zip_locality
    "#{postal_code} #{locality}"
  end

  def zip_locality=(value)
    self.postal_code, self.locality = value.split(' ', 2)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
has_vcards-0.20.3 app/models/address.rb
has_vcards-0.20.2 app/models/address.rb
has_vcards-0.20.1 app/models/address.rb
has_vcards-0.20.0 app/models/address.rb