Class: Address

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/address.rb

Instance Method Summary collapse

Instance Method Details

#country_nameObject



9
10
11
# File 'app/models/address.rb', line 9

def country_name
  Carmen::country_name(country)
end

#filled_in?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/models/address.rb', line 21

def filled_in?
  address? && country?
end

#nameObject



25
26
27
28
29
30
# File 'app/models/address.rb', line 25

def name
  [].tap do |out|
    out << firstname if firstname.present?
    out << lastname if lastname.present?
  end.join(' ')
end

#orderObject



13
14
15
# File 'app/models/address.rb', line 13

def order
  order_as_shipping.present? ? order_as_shipping : order_as_billing
end

#partsObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/address.rb', line 32

def parts
  [].tap do |out|
    out << name
    if address.present?
      address.split("\n").each do |line|
        out << line
      end
    end
    out << city if city.present?
    out << state_province_region if state_province_region.present?
    out << zip_postal_code if zip_postal_code.present?
    out << country_name if country.present?
  end
end

#readable_partsObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/address.rb', line 47

def readable_parts
  [].tap do |out|
    out << name

    if address.present?
      address.split("\n").each do |line|
        out << line
      end
    end
    
    last_line = []
    last_line << city if city.present?
    last_line << state_province_region if state_province_region.present?
    last_line << zip_postal_code if zip_postal_code.present?

    out << last_line.join(', ')
    out << country_name if country.present?
  end
end

#shipping_rulesObject



17
18
19
# File 'app/models/address.rb', line 17

def shipping_rules
  ShippingRule.for_country(country)
end