postal_address 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c4b666d6627a5f91c38df6261e7422c38433c618
4
+ data.tar.gz: fbb5d39591acd9e33f0d201902c8ec2615595098
5
+ SHA512:
6
+ metadata.gz: 3ff76d7b99f8be39c853d78510e3ac1ff6b6ba3499f86c50fe64bddccc0cccb63aa1108d25a1dd77be03af4f163784de2871b13e9326d11fcd9498d7a27c2023
7
+ data.tar.gz: 0f1148e1e66eebc674b4bfb0c8badca106fbd7a033e46d33001c1db1a5b2fc92a417fcbeb6889e67fa17be1a986acbc3eb09b549b989a6e26008f1262ddcb3e7
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in postal_address.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kevin Melchert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # PostalAddress
2
+
3
+ International postal address formatting
4
+
5
+ [![Build Status](https://travis-ci.org/max-power/postal_address.png)](https://travis-ci.org/max-power/postal_address)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'postal_address'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install postal_address
20
+
21
+ ## Usage
22
+
23
+ address = {
24
+ recipient: 'Tobias Füncke',
25
+ street: '101 Broadway',
26
+ city: 'New York City',
27
+ zip: '10002',
28
+ state: 'NY',
29
+ country_code: 'us'
30
+ }
31
+
32
+ PostalAddress.new(address).to_s
33
+
34
+ Set a home country (country names are not display for those addresses)
35
+
36
+ PostalAddress.home_country = 'de'
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = 'spec/**/*_spec.rb'
6
+ t.libs << 'spec'
7
+ end
8
+
9
+ desc "Run tests"
10
+ task :default => :test
@@ -0,0 +1,66 @@
1
+ ---
2
+ ae: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
3
+ ar: "%{recipient}\n%{street}\n%{zip} %{city}\n%{state}\n%{country}"
4
+ at: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
5
+ au: "%{recipient}\n%{street}\n%{city} %{state} %{zip}\n%{country}"
6
+ ba: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
7
+ be: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
8
+ bg: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
9
+ bh: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
10
+ br: "%{recipient}\n%{street}\n%{zip} %{city} %{state}\n%{country}"
11
+ ca: "%{recipient}\n%{street}\n%{city} %{state} %{zip}\n%{country}"
12
+ ch: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
13
+ cn: "%{recipient}\n%{street}\n%{zip} %{city} %{state}\n%{country}"
14
+ cz: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
15
+ de: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
16
+ dk: "%{recipient}\n%{street}\n%{zip} %{city}\n%{state}\n%{country}"
17
+ eg: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
18
+ es: "%{recipient}\n%{street}\n%{zip} %{city} %{state}\n%{country}"
19
+ fi: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
20
+ fr: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
21
+ gb: "%{recipient}\n%{street}\n%{city}\n%{state}\n%{zip}\n%{country}"
22
+ gl: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
23
+ gr: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
24
+ hk: "%{recipient}\n%{street}\n%{zip} %{city} %{state}\n%{country}"
25
+ hr: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
26
+ hu: "%{recipient}\n%{city}\n%{street}\n%{zip}\n%{country}"
27
+ id: "%{recipient}\n%{street}\n%{city}\n%{state} %{zip}\n%{country}"
28
+ ie: "%{recipient}\n%{street}\n%{city} %{state} %{zip}\n%{country}"
29
+ il: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
30
+ in: "%{recipient}\n%{street}\n%{state}\n%{city} %{zip}\n%{country}"
31
+ is: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
32
+ it: "%{recipient}\n%{street}\n%{zip} %{city} %{state}\n%{country}"
33
+ jo: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
34
+ jp: "〒%{zip}\n%{state}%{city}%{street}\n%{recipient}\n%{country}"
35
+ kr: "%{recipient}\n%{street}\n%{city} %{state}\n%{zip}\n%{country}"
36
+ kw: "%{recipient}\n%{street}\n%{zip} %{city}\n%{state}\n%{country}"
37
+ lb: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
38
+ li: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
39
+ lu: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
40
+ mk: "%{recipient}\n%{street}\n%{city} %{zip}\n%{country}"
41
+ mx: "%{recipient}\n%{street}\n%{zip} %{city} %{state}\n%{country}"
42
+ nc: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
43
+ nl: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
44
+ "no": "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
45
+ nz: "%{recipient}\n%{street}\n%{state}\n%{city} %{zip}\n%{country}"
46
+ om: "%{recipient}\n%{street}\n%{zip} %{city}\n%{state}\n%{country}"
47
+ ph: "%{recipient}\n%{street} %{state}\n%{zip} %{city}\n%{country}"
48
+ pl: "%{recipient}\n%{street}\n%{zip} %{city}\n%{state}\n%{country}"
49
+ pt: "%{recipient}\n%{street}\n%{zip} %{city} %{state}\n%{country}"
50
+ qa: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
51
+ ro: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
52
+ ru: "%{recipient}\n%{zip} %{city}\n%{street}\n%{country}"
53
+ sa: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
54
+ se: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
55
+ sg: "%{recipient}\n%{street}\n%{city} %{zip}\n%{country}"
56
+ si: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
57
+ sk: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
58
+ sy: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
59
+ th: "%{recipient}\n%{street}\n%{city} %{state} %{zip}\n%{country}"
60
+ tr: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
61
+ tw: "%{recipient}\n%{street}\n%{city} %{state} %{zip}\n%{country}"
62
+ ua: "%{recipient}\n%{street}\n%{city} %{state}\n%{zip}\n%{country}"
63
+ us: "%{recipient}\n%{street}\n%{city} %{state} %{zip}\n%{country}"
64
+ ye: "%{recipient}\n%{street}\n%{zip} %{city}\n%{country}"
65
+ yu: "%{recipient}\n%{street}\n%{zip} %{city}\n\n%{state}\n%{country}"
66
+ za: "%{recipient}\n%{street}\n%{city}\n%{state}\n%{zip}\n%{country}"
@@ -0,0 +1,246 @@
1
+ ---
2
+ ad: Andorra
3
+ ae: United Arab Emirates
4
+ af: Afghanistan
5
+ ag: Antigua and Barbuda
6
+ ai: Anguilla
7
+ al: Albania
8
+ am: Armenia
9
+ an: Netherlands Antilles
10
+ ao: Angola
11
+ aq: Antarctica
12
+ ar: Argentina
13
+ as: American Samoa
14
+ at: Austria
15
+ au: Australia
16
+ aw: Aruba
17
+ az: Azerbaijan
18
+ ba: Bosnia and Herzegovina
19
+ bb: Barbados
20
+ bd: Bangladesh
21
+ be: Belgium
22
+ bf: Burkina Faso
23
+ bg: Bulgaria
24
+ bh: Bahrain
25
+ bi: Burundi
26
+ bj: Benin
27
+ bl: Saint Barthélemy
28
+ bm: Bermuda
29
+ bn: Brunei Darussalam
30
+ bo: Bolivia
31
+ br: Brazil
32
+ bs: Bahamas
33
+ bt: Bhutan
34
+ bv: Bouvet Island
35
+ bw: Botswana
36
+ by: Belarus
37
+ bz: Belize
38
+ ca: Canada
39
+ cc: Cocos (Keeling) Islands
40
+ cd: The Democratic Republic of the Congo
41
+ cf: Central African Republic
42
+ cg: Congo
43
+ ch: Switzerland
44
+ ci: Côte d'Ivoire
45
+ ck: Cook Islands
46
+ cl: Chile
47
+ cm: Cameroon
48
+ cn: China
49
+ co: Colombia
50
+ cr: Costa Rica
51
+ cu: Cuba
52
+ cv: Cape Verde
53
+ cx: Christmas Island
54
+ cy: Cyprus
55
+ cz: Czech Republic
56
+ de: Germany
57
+ dj: Djibouti
58
+ dk: Denmark
59
+ dm: Dominica
60
+ do: Dominican Republic
61
+ dz: Algeria
62
+ ec: Ecuador
63
+ ee: Estonia
64
+ eg: Egypt
65
+ eh: Western Sahara
66
+ er: Eritrea
67
+ es: Spain
68
+ ic: Spain (Canary Islands)
69
+ et: Ethiopia
70
+ fi: Finland
71
+ fj: Fiji
72
+ fk: Falkland Islands (Malvinas)
73
+ fm: Micronesia
74
+ fo: Faroe Islands
75
+ fr: France
76
+ ga: Gabon
77
+ gb: United Kingdom
78
+ gd: Grenada
79
+ ge: Georgia
80
+ gf: French Guiana
81
+ gg: Guernsey
82
+ gh: Ghana
83
+ gi: Gibraltar
84
+ gl: Greenland
85
+ gm: Gambia
86
+ gn: Guinea
87
+ gp: Guadeloupe
88
+ gq: Equatorial Guinea
89
+ gr: Greece
90
+ gs: South Georgia and the South Sandwich Islands
91
+ gt: Guatemala
92
+ gu: Guam
93
+ gw: Guinea-Bissau
94
+ gy: Guyana
95
+ hk: Hong Kong
96
+ hm: Heard Island and McDonald Islands
97
+ hn: Honduras
98
+ hr: Croatia
99
+ ht: Haiti
100
+ hu: Hungary
101
+ id: Indonesia
102
+ ie: Ireland
103
+ il: Israel
104
+ im: Isle of Man
105
+ in: India
106
+ io: British Indian Ocean Territory
107
+ iq: Iraq
108
+ ir: Iran
109
+ is: Iceland
110
+ it: Italy
111
+ je: Jersey
112
+ jm: Jamaica
113
+ jo: Jordan
114
+ jp: Japan
115
+ ke: Kenya
116
+ kg: Kyrgyzstan
117
+ kh: Cambodia
118
+ ki: Kiribati
119
+ km: Comoros
120
+ kn: Saint Kitts and Nevis
121
+ kp: North Korea
122
+ kr: South Korea
123
+ kw: Kuwait
124
+ ky: Cayman Islands
125
+ kz: Kazakhstan
126
+ la: Laos
127
+ lb: Lebanon
128
+ lc: Saint Lucia
129
+ li: Liechtenstein
130
+ lk: Sri Lanka
131
+ lr: Liberia
132
+ ls: Lesotho
133
+ lt: Lithuania
134
+ lu: Luxembourg
135
+ lv: Latvia
136
+ ly: Libyan Arab Jamahiriya
137
+ ma: Morocco
138
+ mc: Monaco
139
+ md: Moldova
140
+ me: Montenegro
141
+ mf: Saint Martin
142
+ mg: Madagascar
143
+ mh: Marshall Islands
144
+ mk: Macedonia
145
+ ml: Mali
146
+ mm: Myanmar
147
+ mn: Mongolia
148
+ mo: Macao
149
+ mp: Northern Mariana Islands
150
+ mq: Martinique
151
+ mr: Mauritania
152
+ ms: Montserrat
153
+ mt: Malta
154
+ mu: Mauritius
155
+ mv: Maldives
156
+ mw: Malawi
157
+ mx: Mexico
158
+ my: Malaysia
159
+ mz: Mozambique
160
+ na: Namibia
161
+ nc: New Caledonia
162
+ ne: Niger
163
+ nf: Norfolk Island
164
+ ng: Nigeria
165
+ ni: Nicaragua
166
+ nl: Netherlands
167
+ "no": Norway
168
+ np: Nepal
169
+ nr: Nauru
170
+ nu: Niue
171
+ nz: New Zealand
172
+ om: Oman
173
+ pa: Panama
174
+ pe: Peru
175
+ pf: French Polynesia
176
+ pg: Papua New Guinea
177
+ ph: Philippines
178
+ pk: Pakistan
179
+ pl: Poland
180
+ pm: Saint Pierre and Miquelon
181
+ pn: Pitcairn
182
+ pr: Puerto Rico
183
+ ps: Palestinian Territory
184
+ pt: Portugal
185
+ pw: Palau
186
+ py: Paraguay
187
+ qa: Qatar
188
+ re: Réunion
189
+ ro: Romania
190
+ rs: Serbia
191
+ ru: Russian Federation
192
+ rw: Rwanda
193
+ sa: Saudi Arabia
194
+ sb: Solomon Islands
195
+ sc: Seychelles
196
+ sd: Sudan
197
+ se: Sweden
198
+ sg: Singapore
199
+ sh: Saint Helena
200
+ si: Slovenia
201
+ sj: Svalbard and Jan Mayen
202
+ sk: Slovakia
203
+ sl: Sierra Leone
204
+ sm: San Marino
205
+ sn: Senegal
206
+ so: Somalia
207
+ sr: Suriname
208
+ st: Sao Tome and Principe
209
+ sv: El Salvador
210
+ sy: Syrian Arab Republic
211
+ sz: Swaziland
212
+ tc: Turks and Caicos Islands
213
+ td: Chad
214
+ tf: French Southern Territories
215
+ tg: Togo
216
+ th: Thailand
217
+ tj: Tajikistan
218
+ tk: Tokelau
219
+ tl: Timor-Leste
220
+ tm: Turkmenistan
221
+ tn: Tunisia
222
+ to: Tonga
223
+ tr: Turkey
224
+ tt: Trinidad and Tobago
225
+ tv: Tuvalu
226
+ tw: Taiwan
227
+ tz: Tanzania
228
+ ua: Ukraine
229
+ ug: Uganda
230
+ us: United States of America
231
+ uy: Uruguay
232
+ uz: Uzbekistan
233
+ va: Vatican City State
234
+ vc: Saint Vincent and the Grenadines
235
+ ve: Venezuela
236
+ vg: British Virgin Islands
237
+ vi: U.S. Virgin Islands
238
+ vn: Vietnam
239
+ vu: Vanuatu
240
+ wf: Wallis and Futuna
241
+ ws: Samoa
242
+ ye: Yemen
243
+ yt: Mayotte
244
+ za: South Africa
245
+ zm: Zambia
246
+ zw: Zimbabwe
@@ -0,0 +1,3 @@
1
+ class PostalAddress
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,54 @@
1
+ require "postal_address/version"
2
+ require "yaml"
3
+
4
+ class PostalAddress
5
+ class << self
6
+ attr_reader :home_country
7
+
8
+ def formats
9
+ @formats ||= YAML.load_file("data/address_formats.yml")
10
+ end
11
+
12
+ def country_names
13
+ @country_names ||= YAML.load_file("data/country_names.yml")
14
+ end
15
+
16
+ def home_country=(code)
17
+ @home_country = code && code.to_s.downcase
18
+ end
19
+ end
20
+
21
+ attr_accessor :recipient, :street, :zip, :city, :state, :country_code
22
+
23
+ def initialize(attributes={})
24
+ attributes.each do |attr, value|
25
+ self.public_send("#{attr}=", value) if self.respond_to?("#{attr}=")
26
+ end if attributes
27
+ end
28
+
29
+ def to_s
30
+ (format % to_h).strip
31
+ end
32
+
33
+ def to_h
34
+ { :recipient=>recipient, :street=>street, :zip=>zip, :city=>city, :state=>state, :country=>country }
35
+ end
36
+
37
+ def country_code=(code)
38
+ @country_code = code && code.to_s.downcase
39
+ end
40
+
41
+ def country
42
+ self.class.country_names[country_code] unless in_home_country?
43
+ end
44
+
45
+ private
46
+
47
+ def format
48
+ self.class.formats[country_code] || self.class.formats[state ? 'us' : 'de']
49
+ end
50
+
51
+ def in_home_country?
52
+ self.class.home_country == country_code
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'postal_address/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "postal_address"
8
+ spec.version = PostalAddress::VERSION
9
+ spec.authors = ["Kevin Melchert"]
10
+ spec.email = ["kevin.melchert@gmail.com"]
11
+ spec.description = %q{International postal address formatting}
12
+ spec.summary = %q{International postal address formatting}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency "virtus"
25
+ end
@@ -0,0 +1,84 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe PostalAddress do
5
+ it "should load the formats" do
6
+ PostalAddress.formats.wont_be :empty?
7
+ PostalAddress.formats.must_be_kind_of Hash
8
+ end
9
+
10
+ it "should load the country_name" do
11
+ PostalAddress.country_names.wont_be :empty?
12
+ PostalAddress.country_names.must_be_kind_of Hash
13
+ end
14
+
15
+ it "should read/write home country" do
16
+ PostalAddress.home_country = 'de'
17
+ PostalAddress.home_country.must_equal 'de'
18
+ end
19
+
20
+ it "should read/write home country and convert to string and lower case" do
21
+ PostalAddress.home_country = :DE
22
+ PostalAddress.home_country.must_equal 'de'
23
+ end
24
+
25
+ describe "Instance" do
26
+ before {
27
+ PostalAddress.home_country = nil
28
+ }
29
+
30
+ let(:address) do
31
+ PostalAddress.new({
32
+ recipient: 'Tobias Füncke',
33
+ street: '101 Broadway',
34
+ city: 'New York City',
35
+ zip: '10002',
36
+ state: 'NY',
37
+ country_code: 'us'
38
+ })
39
+ end
40
+
41
+ it "should respond to to_h" do
42
+ r = address.to_h
43
+ r.must_be_kind_of Hash
44
+ r.keys.length.must_equal 6
45
+ end
46
+
47
+ it "should format to US format" do
48
+ address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002\nUnited States of America"
49
+ end
50
+
51
+ it "should format to FR format" do
52
+ address.country_code = 'fr'
53
+ address.city = 'Paris'
54
+ address.to_s.must_equal "Tobias Füncke\n101 Broadway\n10002 Paris\nFrance"
55
+ end
56
+
57
+ it "should format to DE format" do
58
+ address.country_code = 'de'
59
+ address.city = 'Berlin'
60
+ address.to_s.must_equal "Tobias Füncke\n101 Broadway\n10002 Berlin\nGermany"
61
+ end
62
+
63
+ it "should not print the country if in home country" do
64
+ PostalAddress.home_country = 'us'
65
+ address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002"
66
+ end
67
+
68
+ it "should print the country if not in home country" do
69
+ PostalAddress.home_country = 'de'
70
+ address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002\nUnited States of America"
71
+ end
72
+
73
+ it "should use default formatting with state if format for country code is not available" do
74
+ address.country_code = nil
75
+ address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002"
76
+ end
77
+
78
+ it "should use default formatting without state if format for country code is not available" do
79
+ address.country_code = nil
80
+ address.state = nil
81
+ address.to_s.must_equal "Tobias Füncke\n101 Broadway\n10002 New York City"
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+
5
+ require 'minitest/autorun'
6
+ require 'minitest/spec'
7
+ require 'postal_address'
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'virtus'
4
+
5
+ class Address
6
+ include Virtus
7
+ attribute :id, Integer
8
+ attribute :recipient, String
9
+ attribute :street, String
10
+ attribute :zip, String
11
+ attribute :city, String
12
+ attribute :state, String
13
+ attribute :country_code, String
14
+ attribute :geolocation, Array
15
+
16
+ def postal_address
17
+ PostalAddress.new(self.attributes).to_s
18
+ end
19
+ end
20
+
21
+ describe Address do
22
+ let(:address) {
23
+ Address.new({
24
+ id: 1001,
25
+ recipient: 'Tobias Füncke',
26
+ street: '101 Broadway',
27
+ city: 'New York City',
28
+ zip: '10002',
29
+ state: 'NY',
30
+ country_code: 'us',
31
+ geolocation: [13,52]
32
+ })
33
+ }
34
+
35
+ it "should work" do
36
+ PostalAddress.home_country = 'us'
37
+ address.postal_address.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002"
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: postal_address
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Melchert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: International postal address formatting
70
+ email:
71
+ - kevin.melchert@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - data/address_formats.yml
83
+ - data/country_names.yml
84
+ - lib/postal_address.rb
85
+ - lib/postal_address/version.rb
86
+ - postal_address.gemspec
87
+ - spec/postal_address_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/virtus_integration_spec.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: International postal address formatting
114
+ test_files:
115
+ - spec/postal_address_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/virtus_integration_spec.rb