Sha256: a39c69255b338e51c643103e20fb73626a46c58c17baf788b208562a47f47a2c

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

module Renalware
  class Address < ApplicationRecord
    belongs_to :country, class_name: "System::Country"
    validates :email, email: true, allow_blank: true
    delegate :uk?, to: :country, allow_nil: true
    validates_with AddressValidator

    belongs_to :addressable, polymorphic: true

    def self.reject_if_blank
      lambda { |attrs|
        %w(name organisation_name street_1 street_2 street_3 town county postcode)
          .all? { |a| attrs[a].blank? }
      }
    end

    def copy_from(source)
      return self if source.blank?
      self.name = source.name
      self.organisation_name = source.organisation_name
      self.street_1 = source.street_1
      self.street_2 = source.street_2
      self.street_3 = source.street_3
      self.town = source.town
      self.county = source.county
      self.postcode = source.postcode
      self.country = source.country
      self
    end

    def to_s
      [name, organisation_name, street_1, street_2, street_3, town, county, postcode, country]
        .reject(&:blank?).join(", ")
    end

    def street
      [street_1, street_2, street_3].compact.join(", ")
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
renalware-core-2.0.9 app/values/renalware/address.rb
renalware-core-2.0.8 app/values/renalware/address.rb
renalware-core-2.0.7 app/values/renalware/address.rb
renalware-core-2.0.5 app/values/renalware/address.rb
renalware-core-2.0.4 app/values/renalware/address.rb
renalware-core-2.0.3 app/values/renalware/address.rb
renalware-core-2.0.2 app/values/renalware/address.rb
renalware-core-2.0.1 app/values/renalware/address.rb
renalware-core-2.0.0 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc13 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc11 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc10 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc9 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc8 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc7 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc6 app/values/renalware/address.rb
renalware-core-2.0.0.pre.rc5 app/values/renalware/address.rb