mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 15:19:38 +02:00
* Fix: No comma when locality is empty * better cleanup on address string * fix test to one-liner * add more testing
18 lines
434 B
Ruby
18 lines
434 B
Ruby
class Address < ApplicationRecord
|
|
belongs_to :addressable, polymorphic: true
|
|
|
|
def to_s
|
|
string = I18n.t("address.format",
|
|
line1: line1,
|
|
line2: line2,
|
|
county: county,
|
|
locality: locality,
|
|
region: region,
|
|
country: country,
|
|
postal_code: postal_code
|
|
)
|
|
|
|
# Clean up the string to maintain I18n comma formatting
|
|
string.split(",").map(&:strip).reject(&:empty?).join(", ")
|
|
end
|
|
end
|