Sha256: 5f1207a09c222c7cddc95527d7eb6bb23fc111afa5b770c22f7ebd4a81ad6094

Contents?: true

Size: 808 Bytes

Versions: 1

Compression:

Stored size: 808 Bytes

Contents

class Address < ActiveRecord::Base

  belongs_to :address_type, optional: true
  belongs_to :addressable, polymorphic: true, optional: true

  before_save :validate_and_sanitize_us_address
  
  def address_concatenated
    [self.full_street_address, self.city, self.state_or_province, self.postal_code].join(', ')
  end
  
  def validate_and_sanitize_us_address
    if (address = StreetAddress::US.parse(self.address_concatenated))
      self.street_number = address.number
      self.street_dir_prefix = address.prefix
      self.street_name = address.street
      self.street_suffix = address.street_type
      self.street_dir_suffix = address.suffix
      self.unit_number = address.unit unless address.unit.blank?
      self.state_or_province = address.state
      self.country = 'US'
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reso-0.1.6.7 app/models/address.rb