snail 2.0.0 → 2.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +17 -0
- data/assets/DE.yml +1 -1
- data/assets/NA.yml +1 -0
- data/lib/snail.rb +61 -57
- data/lib/snail/constants.rb +503 -507
- data/lib/snail/initializable.rb +3 -6
- data/lib/snail/version.rb +1 -1
- data/test/snail_test.rb +42 -2
- metadata +3 -4
data/lib/snail/initializable.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
class Snail
|
2
2
|
module Initializable
|
3
|
-
def initialize(attrs = {}
|
3
|
+
def initialize(attrs = {})
|
4
4
|
attrs.each do |k, v|
|
5
5
|
m = "#{k}="
|
6
|
-
|
7
|
-
|
8
|
-
else
|
9
|
-
raise UnknownAttribute.new(k)
|
10
|
-
end
|
6
|
+
raise UnknownAttribute, k unless respond_to? m
|
7
|
+
send(m, v)
|
11
8
|
end
|
12
9
|
yield self if block_given?
|
13
10
|
end
|
data/lib/snail/version.rb
CHANGED
data/test/snail_test.rb
CHANGED
@@ -72,20 +72,48 @@ class SnailTest < Snail::TestCase
|
|
72
72
|
assert s.city_line.match(/NY 12345/)
|
73
73
|
end
|
74
74
|
|
75
|
-
test "does not include country name for domestic addresses" do
|
75
|
+
test "does not include country name for domestic addresses by default" do
|
76
76
|
s = Snail.new(@us.merge(:origin => 'US'))
|
77
77
|
assert !s.to_s.match(/United States/i)
|
78
78
|
s = Snail.new(@ca.merge(:origin => 'CA'))
|
79
79
|
assert !s.to_s.match(/Canada/i)
|
80
80
|
end
|
81
81
|
|
82
|
-
test "includes country name for
|
82
|
+
test "includes country name for domestic addresses if with_country parameter is true" do
|
83
|
+
s = Snail.new(@us.merge(:origin => 'US'))
|
84
|
+
assert s.to_s(with_country: true).match(/United States/i)
|
85
|
+
s = Snail.new(@ca.merge(:origin => 'CA'))
|
86
|
+
assert s.to_s(with_country: true).match(/Canada/i)
|
87
|
+
end
|
88
|
+
|
89
|
+
test "does not include country name for domestic addresses if with_country parameter is false" do
|
90
|
+
s = Snail.new(@us.merge(:origin => 'US'))
|
91
|
+
assert !s.to_s(with_country: false).match(/United States/i)
|
92
|
+
s = Snail.new(@ca.merge(:origin => 'CA'))
|
93
|
+
assert !s.to_s(with_country: false).match(/Canada/i)
|
94
|
+
end
|
95
|
+
|
96
|
+
test "includes country name for international addresses by default" do
|
83
97
|
s = Snail.new(@us.merge(:origin => 'CA'))
|
84
98
|
assert s.to_s.match(/United States/i)
|
85
99
|
s = Snail.new(@ca.merge(:origin => 'US'))
|
86
100
|
assert s.to_s.match(/Canada/i)
|
87
101
|
end
|
88
102
|
|
103
|
+
test "includes country name for international addresses if with_country parameter is true" do
|
104
|
+
s = Snail.new(@us.merge(:origin => 'CA'))
|
105
|
+
assert s.to_s(with_country: true).match(/United States/i)
|
106
|
+
s = Snail.new(@ca.merge(:origin => 'US'))
|
107
|
+
assert s.to_s(with_country: true).match(/Canada/i)
|
108
|
+
end
|
109
|
+
|
110
|
+
test "does not include country name for international addresses if with_country parameter is false" do
|
111
|
+
s = Snail.new(@us.merge(:origin => 'CA'))
|
112
|
+
assert !s.to_s(with_country: false).match(/United States/i)
|
113
|
+
s = Snail.new(@ca.merge(:origin => 'US'))
|
114
|
+
assert !s.to_s(with_country: false).match(/Canada/i)
|
115
|
+
end
|
116
|
+
|
89
117
|
test "includes translated country name for international addresses" do
|
90
118
|
s = Snail.new(@us.merge(:origin => 'FR'))
|
91
119
|
assert s.to_s.match(/ÉTATS-UNIS/i)
|
@@ -118,12 +146,24 @@ class SnailTest < Snail::TestCase
|
|
118
146
|
assert_equal "John Doe\n12345 5th St\nSomewheres NY 12345\nCANADA", s.to_s
|
119
147
|
end
|
120
148
|
|
149
|
+
test "to_s ireland doesn't show a linebreak if zip is empty" do
|
150
|
+
s = Snail.new(@ie.merge(:zip => ""))
|
151
|
+
puts s.to_s
|
152
|
+
assert_equal "John Doe\n12345 5th St\nSomewheres, Dublin\nIRELAND", s.to_s
|
153
|
+
end
|
154
|
+
|
121
155
|
test "to_html" do
|
122
156
|
s = Snail.new(@ca)
|
123
157
|
s.name = 'John & Jane Doe'
|
124
158
|
assert_equal "John & Jane Doe<br />12345 5th St<br />Somewheres NY 12345<br />CANADA", s.to_html
|
125
159
|
assert s.to_html.html_safe?
|
126
160
|
end
|
161
|
+
|
162
|
+
test "to_html ireland doesn't show a linebreak if zip is empty" do
|
163
|
+
s = Snail.new(@ie.merge(:zip => ""))
|
164
|
+
s.name = 'John & Jane Doe'
|
165
|
+
assert_equal "John & Jane Doe<br />12345 5th St<br />Somewheres, Dublin<br />IRELAND", s.to_html
|
166
|
+
end
|
127
167
|
end
|
128
168
|
|
129
169
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lance Ivy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -310,8 +310,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
310
310
|
- !ruby/object:Gem::Version
|
311
311
|
version: '0'
|
312
312
|
requirements: []
|
313
|
-
|
314
|
-
rubygems_version: 2.4.5
|
313
|
+
rubygems_version: 3.0.3
|
315
314
|
signing_key:
|
316
315
|
specification_version: 4
|
317
316
|
summary: Easily format snail mail addresses for international delivery
|