Sha256: 4f53e7cb46762465f3bcbdcc78848d5ed8abf384bd36cbfc7fcbaeaab7aafb3a

Contents?: true

Size: 1015 Bytes

Versions: 3

Compression:

Stored size: 1015 Bytes

Contents

module Comable
  class Address < ActiveRecord::Base
    belongs_to :customer, class_name: Comable::Customer.name, autosave: false

    validates :family_name, presence: true, length: { maximum: 255 }
    validates :first_name, presence: true, length: { maximum: 255 }
    validates :zip_code, presence: true, length: { maximum: 8 }
    validates :state_name, presence: true, length: { maximum: 255 }
    validates :city, presence: true, length: { maximum: 255 }
    validates :detail, length: { maximum: 255 }
    validates :phone_number, length: { maximum: 18 }

    class << self
      def find_or_clone(address)
        find { |obj| obj.same_as? address } || address.clone
      end
    end

    def same_as?(address)
      attributes_without_id == address.attributes_without_id
    end

    def clone
      self.class.new(attributes_without_id)
    end

    def attributes_without_id
      attributes.except('id', 'customer_id')
    end

    def full_name
      "#{family_name} #{first_name}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
comable_core-0.3.2 app/models/comable/address.rb
comable_core-0.3.1 app/models/comable/address.rb
comable_core-0.3.0 app/models/comable/address.rb