snail 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/snail.rb +5 -0
- data/lib/snail/configurable.rb +8 -3
- data/test/snail_test.rb +5 -0
- metadata +2 -2
data/lib/snail.rb
CHANGED
@@ -14,6 +14,8 @@ class Snail
|
|
14
14
|
|
15
15
|
# this will be raised whenever formatting or validation is run on an unsupported or unknown country
|
16
16
|
class UnknownCountryError < ArgumentError; end
|
17
|
+
# this will be raised whenever initialization doesn't recognize a key
|
18
|
+
class UnknownAttribute < ArgumentError; end
|
17
19
|
|
18
20
|
# My made-up standard fields.
|
19
21
|
attr_accessor :name
|
@@ -28,7 +30,10 @@ class Snail
|
|
28
30
|
{
|
29
31
|
:full_name => :name,
|
30
32
|
:street => :line_1,
|
33
|
+
:street_1 => :line_1,
|
34
|
+
:street_2 => :line_2,
|
31
35
|
:town => :city,
|
36
|
+
:locality => :city,
|
32
37
|
:state => :region,
|
33
38
|
:province => :region,
|
34
39
|
:zip => :postal_code,
|
data/lib/snail/configurable.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
class Snail
|
2
2
|
module Configurable
|
3
|
-
def initialize(
|
4
|
-
|
5
|
-
|
3
|
+
def initialize(attrs = {}, &block)
|
4
|
+
attrs.each do |k, v|
|
5
|
+
m = "#{k}="
|
6
|
+
if respond_to? m
|
7
|
+
self.send(m, v)
|
8
|
+
else
|
9
|
+
raise UnknownAttribute.new(k)
|
10
|
+
end
|
6
11
|
end
|
7
12
|
yield self if block_given?
|
8
13
|
end
|
data/test/snail_test.rb
CHANGED
@@ -35,8 +35,13 @@ class SnailTest < ActiveSupport::TestCase
|
|
35
35
|
assert_equal 'Somewheres', s.city
|
36
36
|
end
|
37
37
|
|
38
|
+
test "aliases common street names" do
|
39
|
+
assert_equal Snail.new(:street_1 => "123 Foo St").line_1, Snail.new(:line_1 => "123 Foo St").line_1
|
40
|
+
end
|
41
|
+
|
38
42
|
test "aliases common city synonyms" do
|
39
43
|
assert_equal Snail.new(:town => "Somewheres").city, Snail.new(:city => "Somewheres").city
|
44
|
+
assert_equal Snail.new(:locality => "Somewheres").city, Snail.new(:city => "Somewheres").city
|
40
45
|
end
|
41
46
|
|
42
47
|
test "aliases common region synonyms" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: International snail mail addressing is a pain. This begins to make it
|
15
15
|
easier.
|