Initial commit

This commit is contained in:
Senad Uka
2020-05-31 22:38:19 +02:00
commit 858fafc3c5
1280 changed files with 65918 additions and 0 deletions

53
app/models/address.rb Normal file
View File

@@ -0,0 +1,53 @@
class Address
attr_accessor :street1, :street2, :city, :state, :zip, :country
def initialize(street1, street2, city, state, zip, country)
@street1 = street1
@street2 = street2
@city = city
@state = state
@zip = zip
@country = country
end
def to_s(format: nil)
case format
when :full
join_with_newline(
street1,
street2,
join_with_comma(city, state_and_zip),
country
)
when :condensed
join_with_newline(
join_with_comma(street1, street2),
join_with_comma(city, state_and_zip, country),
)
else
join_with_comma(street1, street2, city, state_and_zip, country)
end
end
def present?
[street1, street2, city, state, zip, country].any?(&:present?)
end
private
def join_without_blanks(*parts, separator: ", ")
parts.reject(&:blank?).join(separator)
end
def join_with_comma(*parts)
join_without_blanks(*parts)
end
def join_with_newline(*parts)
join_without_blanks(*parts, separator: "\n")
end
def state_and_zip
join_without_blanks(state, zip, separator: " ")
end
end