Skip to content

Commit ef03a57

Browse files
committed
code support for organization formatting
GitHub Issue #34
1 parent 74ec522 commit ef03a57

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

lib/snail.rb

+21-7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def self.lookup_country_iso(val)
4545
attr_accessor :name
4646
alias full_name= name=
4747

48+
attr_accessor :organization
49+
alias company= organization=
50+
4851
attr_accessor :line_1
4952
alias street= line_1=
5053
alias street_1= line_1=
@@ -89,13 +92,14 @@ def international?
8992
def to_s(with_country: nil)
9093
with_country = true if with_country.nil? && international?
9194

92-
[
93-
name,
94-
line_1,
95-
line_2,
96-
city_line,
97-
(country_line if with_country)
98-
]
95+
(
96+
recipient + [
97+
line_1,
98+
line_2,
99+
city_line,
100+
(country_line if with_country)
101+
]
102+
)
99103
.reject { |line| line.nil? || line.empty? }
100104
.join("\n")
101105
end
@@ -164,4 +168,14 @@ def translated_country(origin, country)
164168
path = File.join(File.dirname(File.expand_path(__FILE__)), "../assets/#{origin}.yml")
165169
File.read(path).match(/^#{country}: (.*)$/)[1]
166170
end
171+
172+
# NOTE: this is likely an incomplete list. please contribute!
173+
private def recipient
174+
case country
175+
when 'NL'
176+
[organization, name]
177+
else
178+
[name, organization]
179+
end
180+
end
167181
end

test/snail_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ def setup
164164
s.name = 'John & Jane Doe'
165165
assert_equal "John &amp; Jane Doe<br />12345 5th St<br />Somewheres, Dublin<br />IRELAND", s.to_html
166166
end
167+
168+
test 'name and organization in united states' do
169+
s = Snail.new(country: 'US', name: 'NAME', organization: 'ORGANIZATION', city: 'CITY', region: 'STATE', postal_code: 'CODE')
170+
assert_equal "NAME\nORGANIZATION\nCITY STATE CODE", s.to_s
171+
end
172+
173+
test 'name and organization in netherlands' do
174+
s = Snail.new(country: 'NL', name: 'NAME', organization: 'ORGANIZATION', city: 'CITY', postal_code: 'CODE')
175+
assert_equal "ORGANIZATION\nNAME\nCODE CITY\nNETHERLANDS", s.to_s
176+
end
167177
end
168178

169179

0 commit comments

Comments
 (0)