Sha256: 04777424d5968bdc969fb33b849a67860d779c1715cf1f9f1eb48fa130b10f09

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

# encoding: utf-8

module InvoiceBar
  class Address < ActiveRecord::Base  
    attr_accessible :city, :city_part, :extra_address_line, :postcode, :street, :street_number
  
    validates :city,          :presence => true#, :length => { :maximum => 50 }
    validates :postcode,      :presence => true#, :length => { :in => 3..10 }
    validates :street,        :presence => true#, :length => { :maximum => 50 }
    validates :street_number, :presence => true#, :length => { :maximum => 15 }
  
    # Assosiations
    attr_accessible :addressable_id, :addressable_type
  
    belongs_to :addressable, :polymorphic => true
    
    # Search
    include InvoiceBar::Searchable
  
    def self.searchable_fields
      ['city', 'city_part', 'extra_address_line', 'postcode', 'street', 'street_number']
    end
    
    def empty?
      attributes = ['city', 'city_part', 'street', 'street_number', 'postcode', 'extra_address_line']
    
      attributes.each do |attribute|
        unless eval "self.#{attribute}.blank?"
          return false
        end
      end
    
      return true
    end
  
    # Copies the address and returns a new instance.
    def copy
      Address.new(
        street: street,
        street_number: street_number,
        city: city,
        city_part: city_part,
        postcode: postcode,
        extra_address_line: extra_address_line
      )
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
invoice_bar-0.0.6 app/models/invoice_bar/address.rb
invoice_bar-0.0.5 app/models/invoice_bar/address.rb
invoice_bar-0.0.4 app/models/invoice_bar/address.rb
invoice_bar-0.0.3 app/models/invoice_bar/address.rb
invoice_bar-0.0.2 app/models/invoice_bar/address.rb
invoice_bar-0.0.1 app/models/invoice_bar/address.rb