Class: Checkout::StreetAddress

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::API, ActiveModel::Attributes, ActiveModel::Validations, ActiveModel::Validations::Callbacks, StripAttributes
Defined in:
app/forms/checkout/street_address.rb

Overview

Form object backing the checkout street-address step.

Carries the recipient, street, city/state/postal, and freight-related
delivery flags (liftgate, loading dock, construction site, limited access,
appointment) as ActiveModel attributes with presence validation on the
minimal address fields.

Instance Method Summary collapse

Instance Method Details

#address_complete?Boolean

Whether the minimal set of address fields is filled in.

Returns:

  • (Boolean)

    true when street1, city, state, postal code, and country are all present



48
49
50
# File 'app/forms/checkout/street_address.rb', line 48

def address_complete?
  %i[street1 city state_code postal_code country_iso3].all? { |f| send(f).presence }
end

#address_type_optionsArray<Array(String, String)>

Bare mininum information we need for a valid address

Returns:

  • (Array<Array(String, String)>)

    label/value pairs for the address-type select



38
39
40
41
42
43
# File 'app/forms/checkout/street_address.rb', line 38

def address_type_options
  [['Residential', 'residential'],
   ['Commercial Building with Receiving Dock', 'commercial_building_with_receiving_dock'],
   ['Commercial Building without Receiving Dock', 'commercial_building_without_receiving_dock'],
   ['Construction Site/Limited Access', 'construction_site']]
end

#full_address(include_recipient = true, sep = '.', _attn_override = nil, _hide_country = false, hide_street_2 = false) ⇒ String

Renders the address as a single joined string.

Parameters:

  • include_recipient (Boolean) (defaults to: true)

    prepend the recipient name when present

  • sep (String) (defaults to: '.')

    separator between address parts

  • _attn_override (String, nil) (defaults to: nil)

    unused; kept for signature compatibility

  • _hide_country (Boolean) (defaults to: false)

    unused; kept for signature compatibility

  • hide_street_2 (Boolean) (defaults to: false)

    omit the second street line

Returns:

  • (String)

    the address parts joined with +sep+



60
61
62
63
64
65
66
67
68
69
70
# File 'app/forms/checkout/street_address.rb', line 60

def full_address(include_recipient = true, sep = '.', _attn_override = nil, _hide_country = false, hide_street_2 = false)
  addr = []
  if include_recipient
    addr << recipient.to_s.strip if recipient.present?
  end
  addr << street1.to_s.strip if street1.present?
  addr << street2.to_s.strip unless street2.blank? || hide_street_2
  addr << "#{city.to_s.strip}, #{state_code} #{postal_code.to_s.strip}"
  addr = addr.uniq.compact
  addr.join(sep)
end