biggs 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,40 +1,48 @@
1
- h3. biggs 0.2.2 - 2012-02-06
1
+ ### dev
2
+
3
+ ### 0.3.0 / 2012-06-15
4
+
5
+ * Added country names for countries with default/unknown address format
6
+ * Simplified inclusion of Biggs::ActiveRecordAdapter
7
+ * Changed doc-format from textile to markdown
8
+
9
+ ### 0.2.2 / 2012-02-06
2
10
 
3
11
  * Compatibility with ActiveRecord/Rails 3.2
4
12
 
5
- h3. biggs 0.2.1 - 2011-11-09
13
+ ### 0.2.1 / 2011-11-09
6
14
 
7
15
  * Fixed gemspec activerecord dependency
8
16
 
9
- h3. biggs 0.2.0 - 2011-10-12
17
+ ### 0.2.0 / 2011-10-12
10
18
 
11
19
  * Added Bundler & removed jewler
12
20
  * Fixed Specs
13
21
  * Added NC (New Caledonia)
14
22
 
15
- h3. biggs 0.1.5 - 2010-11-24
23
+ ### 0.1.5 / 2010-11-24
16
24
 
17
25
  * Fixed address format for Norway
18
26
  * Added TH (Thailand)
19
27
 
20
- h3. biggs 0.1.4 - 2009-5-21
28
+ ### 0.1.4 / 2009-5-21
21
29
 
22
30
  * Fixed Specs
23
31
 
24
- h3. biggs 0.1.3 - 2009-3-6
32
+ ### 0.1.3 / 2009-3-6
25
33
 
26
34
  * Correct japanese address format. [hiroshi]
27
35
  * Fixed docs for current API. [hiroshi]
28
36
 
29
- h3. biggs 0.1.2 - 2009-3-4
37
+ ### 0.1.2 / 2009-3-4
30
38
 
31
39
  * Values can now be specified by an array of symbols.
32
40
 
33
- h3. biggs 0.1.1 - 2009-3-3
41
+ ### 0.1.1 / 2009-3-3
34
42
 
35
43
  * Refactored activerecord-adapter to include only basic setup method in ActiveRecord:Base
36
44
 
37
- h3. biggs 0.1.0 - 2009-3-3
45
+ ### 0.1.0 / 2009-3-3
38
46
 
39
47
  * Allow Procs as params in biggs-activerecord-setup.
40
48
  * Cleanup
@@ -1,81 +1,81 @@
1
1
  biggs is a small ruby gem/rails plugin for formatting postal addresses from over 60 countries.
2
2
 
3
- h3. Install
3
+ ### Install
4
4
 
5
5
  As a ruby gem:
6
6
 
7
- sudo gem install yolk-biggs
7
+ sudo gem install yolk-biggs
8
8
 
9
9
  If your rather prefer to install it as a plugin for rails, from your application directory simply run:
10
10
 
11
- script/plugin install git://github.com/yolk/biggs.git
11
+ script/plugin install git://github.com/yolk/biggs.git
12
12
 
13
- h3. Standalone usage
14
-
15
- f = Biggs::Formatter.new
16
-
17
- f.format("de", # <= ISO alpha 2 code
13
+ ### Standalone usage
14
+
15
+ f = Biggs::Formatter.new
16
+
17
+ f.format("de", # <= ISO alpha 2 code
18
18
  :recipient => "Yolk Sebastian Munz & Julia Soergel GbR",
19
19
  :street => "Adalbertstr. 11", # <= street + house number
20
20
  :city => "Berlin",
21
21
  :zip => 10999,
22
22
  :state => "Berlin" # <= state/province/region
23
- )
23
+ )
24
24
 
25
25
  returns
26
26
 
27
- "Yolk Sebastian Munz & Julia Soergel GbR
28
- Adalbertstr. 11
29
- 10999 Berlin
30
- Germany"
31
-
27
+ "Yolk Sebastian Munz & Julia Soergel GbR
28
+ Adalbertstr. 11
29
+ 10999 Berlin
30
+ Germany"
31
+
32
32
  At the moment Biggs::Formatter.new accepts only one option:
33
33
 
34
34
  *blank_county_on* ISO alpha 2 code (single string or array) of countries the formatter should skip the line "country" (for national shipping).
35
35
 
36
- f = Biggs::Formatter.new(:blank_county_on => "de")
36
+ Biggs::Formatter.new(:blank_county_on => "de")
37
37
 
38
38
  With the data from the above example this would return:
39
39
 
40
- "Yolk Sebastian Munz & Julia Soergel GbR
41
- Adalbertstr. 11
42
- 10999 Berlin"
40
+ "Yolk Sebastian Munz & Julia Soergel GbR
41
+ Adalbertstr. 11
42
+ 10999 Berlin"
43
43
 
44
- h3. Usage with Rails and ActiveRecord
44
+ ### Usage with Rails and ActiveRecord
45
45
 
46
- Address < ActiveRecord::Base
46
+ Address < ActiveRecord::Base
47
47
  biggs :postal_address
48
- end
48
+ end
49
49
 
50
50
  This adds the method postal_address to your Address-model, and assumes the presence of the methods/columns recipient, street, city, zip, state, and country to get the address data. Country should return the ISO-code (e.g. 'us', 'fr', 'de').
51
51
 
52
52
  You can customize the method-names biggs will use by passing in a hash of options:
53
53
 
54
- Address < ActiveRecord::Base
54
+ Address < ActiveRecord::Base
55
55
  biggs :postal_address,
56
56
  :zip => :postal_code,
57
57
  :country => :country_code,
58
58
  :street => Proc.new {|address| "#{address.street} #{address.house_number}" }
59
- end
59
+ end
60
60
 
61
61
  You can pass in a symbol to let biggs call a different method on your Address-model, or a Proc-object to create your data on the fly.
62
62
 
63
63
  You can even pass in a array of symbols:
64
64
 
65
- Address < ActiveRecord::Base
65
+ Address < ActiveRecord::Base
66
66
  biggs :postal_address,
67
67
  :recipient => [:company_name, :person_name]
68
- end
69
-
68
+ end
69
+
70
70
  This will call the methods company_name and person_name on your address-instance, remove any blank returned values and join the rest by a line break.
71
71
 
72
72
  To access the formatted address string, simply call the provided method on an address instance:
73
73
 
74
- Address.find(1).postal_address
74
+ Address.find(1).postal_address
75
75
 
76
76
  If you pass in a ISO alpha 2 code as :country that is not supported by biggs, it will choose the US-format for addresses with an state specified, and the french/german format for addresses without an state.
77
77
 
78
- h3. Supported countries
78
+ ### Supported countries
79
79
 
80
80
  biggs knows how to format addresses of over 60 different countries. If you are missing one or find an misstake, feel free to let us know, fork this repository and commit your additions.
81
81
 
@@ -142,9 +142,9 @@ biggs knows how to format addresses of over 60 different countries. If you are m
142
142
  * Ukraine
143
143
  * United Arab Emirates
144
144
  * United Kingdom
145
- * United States
145
+ * United States of America
146
146
  * Yemen
147
147
 
148
- biggs is tested to behave well with Rails 2.2.2.
148
+ biggs is tested to behave well with Rails 3.0
149
149
 
150
- Copyright (c) 2009 Yolk Sebastian Munz & Julia Soergel GbR
150
+ Copyright (c) 2009-2012 Yolk Sebastian Munz & Julia Soergel GbR
@@ -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: Congo, The Democratic Republic of the
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, Federated States of
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, Islamic Republic of
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: Korea, Democratic People's Republic of
122
+ kr: Korea, Republic of
123
+ kw: Kuwait
124
+ ky: Cayman Islands
125
+ kz: Kazakhstan
126
+ la: Lao People's Democratic Republic
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, The Former Yugoslav Republic of
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, Occupied
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, Province of China
227
+ tz: Tanzania, United Republic of
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: Virgin Islands, British
237
+ vi: Virgin Islands, U.S.
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
@@ -7,233 +7,169 @@
7
7
  # * country
8
8
  #
9
9
  ---
10
- ae:
11
- name: United Arab Emirates
12
- format: |-
10
+ ae: |-
13
11
  {{recipient}}
14
12
  {{street}}
15
13
  {{zip}} {{city}}
16
14
  {{country}}
17
- ar:
18
- name: Argentina
19
- format: |-
15
+ ar: |-
20
16
  {{recipient}}
21
17
  {{street}}
22
18
  {{zip}} {{city}}
23
19
  {{state}}
24
20
  {{country}}
25
- at:
26
- name: Austria
27
- format: |-
21
+ at: |-
28
22
  {{recipient}}
29
23
  {{street}}
30
24
  {{zip}} {{city}}
31
25
  {{country}}
32
- au:
33
- name: Australia
34
- format: |-
26
+ au: |-
35
27
  {{recipient}}
36
28
  {{street}}
37
29
  {{city}} {{state}} {{zip}}
38
30
  {{country}}
39
- ba:
40
- name: Bosnia and Herzegovina
41
- format: |-
31
+ ba: |-
42
32
  {{recipient}}
43
33
  {{street}}
44
34
  {{zip}} {{city}}
45
35
  {{country}}
46
- be:
47
- name: Belgium
48
- format: |-
36
+ be: |-
49
37
  {{recipient}}
50
38
  {{street}}
51
39
  {{zip}} {{city}}
52
40
  {{country}}
53
- bg:
54
- name: Bulgaria
55
- format: |-
41
+ bg: |-
56
42
  {{recipient}}
57
43
  {{street}}
58
44
  {{zip}} {{city}}
59
45
  {{country}}
60
- bh:
61
- name: Bahrain
62
- format: |-
46
+ bh: |-
63
47
  {{recipient}}
64
48
  {{street}}
65
49
  {{zip}} {{city}}
66
50
  {{country}}
67
- br:
68
- name: Brazil
69
- format: |-
51
+ br: |-
70
52
  {{recipient}}
71
53
  {{street}}
72
54
  {{zip}} {{city}} {{state}}
73
55
  {{country}}
74
- ca:
75
- name: Canada
76
- format: |-
56
+ ca: |-
77
57
  {{recipient}}
78
58
  {{street}}
79
59
  {{city}} {{state}} {{zip}}
80
60
  {{country}}
81
- ch:
82
- name: Switzerland
83
- format: |-
61
+ ch: |-
84
62
  {{recipient}}
85
63
  {{street}}
86
64
  {{zip}} {{city}}
87
65
  {{country}}
88
- cn:
89
- name: China
90
- format: |-
66
+ cn: |-
91
67
  {{recipient}}
92
68
  {{street}}
93
69
  {{zip}} {{city}} {{state}}
94
70
  {{country}}
95
- cz:
96
- name: Czech
97
- format: |-
71
+ cz: |-
98
72
  {{recipient}}
99
73
  {{street}}
100
74
  {{zip}} {{city}}
101
75
  {{country}}
102
- de:
103
- name: Germany
104
- format: |-
76
+ de: |-
105
77
  {{recipient}}
106
78
  {{street}}
107
79
  {{zip}} {{city}}
108
80
  {{country}}
109
- dk:
110
- name: Denmark
111
- format: |-
81
+ dk: |-
112
82
  {{recipient}}
113
83
  {{street}}
114
84
  {{zip}} {{city}}
115
85
  {{state}}
116
86
  {{country}}
117
- eg:
118
- name: Egypt
119
- format: |-
87
+ eg: |-
120
88
  {{recipient}}
121
89
  {{street}}
122
90
  {{zip}} {{city}}
123
91
  {{country}}
124
- es:
125
- name: Spain
126
- format: |-
92
+ es: |-
127
93
  {{recipient}}
128
94
  {{street}}
129
95
  {{zip}} {{city}} {{state}}
130
96
  {{country}}
131
- fi:
132
- name: Finland
133
- format: |-
97
+ fi: |-
134
98
  {{recipient}}
135
99
  {{street}}
136
100
  {{zip}} {{city}}
137
101
  {{country}}
138
- fr:
139
- name: France
140
- format: |-
102
+ fr: |-
141
103
  {{recipient}}
142
104
  {{street}}
143
105
  {{zip}} {{city}}
144
106
  {{country}}
145
- gb:
146
- name: United Kingdom
147
- format: |-
107
+ gb: |-
148
108
  {{recipient}}
149
109
  {{street}}
150
110
  {{city}}
151
111
  {{state}}
152
112
  {{zip}}
153
113
  {{country}}
154
- gl:
155
- name: Greenland
156
- format: |-
114
+ gl: |-
157
115
  {{recipient}}
158
116
  {{street}}
159
117
  {{zip}} {{city}}
160
118
  {{country}}
161
- gr:
162
- name: Greece
163
- format: |-
119
+ gr: |-
164
120
  {{recipient}}
165
121
  {{street}}
166
122
  {{zip}} {{city}}
167
123
  {{country}}
168
- hk:
169
- name: Hong Kong
170
- format: |-
124
+ hk: |-
171
125
  {{recipient}}
172
126
  {{street}}
173
127
  {{zip}} {{city}} {{state}}
174
128
  {{country}}
175
- hr:
176
- name: Croatia
177
- format: |-
129
+ hr: |-
178
130
  {{recipient}}
179
131
  {{street}}
180
132
  {{zip}} {{city}}
181
133
  {{country}}
182
- hu:
183
- name: Hungary
184
- format: |-
134
+ hu: |-
185
135
  {{recipient}}
186
136
  {{city}}
187
137
  {{street}}
188
138
  {{zip}}
189
139
  {{country}}
190
- id:
191
- name: Indonesia
192
- format: |-
140
+ id: |-
193
141
  {{recipient}}
194
142
  {{street}}
195
143
  {{city}}
196
144
  {{state}} {{zip}}
197
145
  {{country}}
198
- ie:
199
- name: Ireland
200
- format: |-
146
+ ie: |-
201
147
  {{recipient}}
202
148
  {{street}}
203
149
  {{city}} {{state}} {{zip}}
204
150
  {{country}}
205
- il:
206
- name: Israel
207
- format: |-
151
+ il: |-
208
152
  {{recipient}}
209
153
  {{street}}
210
154
  {{zip}} {{city}}
211
155
  {{country}}
212
- in:
213
- name: India
214
- format: |-
156
+ in: |-
215
157
  {{recipient}}
216
158
  {{street}}
217
159
  {{state}}
218
160
  {{city}} {{zip}}
219
161
  {{country}}
220
- is:
221
- name: Iceland
222
- format: |-
162
+ is: |-
223
163
  {{recipient}}
224
164
  {{street}}
225
165
  {{zip}} {{city}}
226
166
  {{country}}
227
- it:
228
- name: Italy
229
- format: |-
167
+ it: |-
230
168
  {{recipient}}
231
169
  {{street}}
232
170
  {{zip}} {{city}} {{state}}
233
171
  {{country}}
234
- jo:
235
- name: Jordan
236
- format: |-
172
+ jo: |-
237
173
  {{recipient}}
238
174
  {{street}}
239
175
  {{zip}} {{city}}
@@ -251,241 +187,176 @@ jo:
251
187
  # 〒163-1480
252
188
  # 東京都新宿区西新宿3-20-2
253
189
  # アップルジャパン株式会社 本社
254
- jp:
255
- name: Japan
256
- format: |-
190
+ jp: |-
257
191
  〒{{zip}}
258
192
  {{state}}{{city}}{{street}}
259
193
  {{recipient}}
260
194
  {{country}}
261
- kr:
262
- name: South Korea
263
- format: |-
195
+ kr: |-
264
196
  {{recipient}}
265
197
  {{street}}
266
198
  {{city}} {{state}}
267
199
  {{zip}}
268
200
  {{country}}
269
- kw:
270
- name: Kuwait
271
- format: |-
201
+ kw: |-
272
202
  {{recipient}}
273
203
  {{street}}
274
204
  {{zip}} {{city}}
275
205
  {{state}}
276
206
  {{country}}
277
- lb:
278
- name: Lebanon
279
- format: |-
207
+ lb: |-
280
208
  {{recipient}}
281
209
  {{street}}
282
210
  {{zip}} {{city}}
283
211
  {{country}}
284
212
  li:
285
- name: Liechtenstein
286
213
  format: |-
287
214
  {{recipient}}
288
215
  {{street}}
289
216
  {{zip}} {{city}}
290
217
  {{country}}
291
- lu:
292
- name: Luxembourg
293
- format: |-
218
+ lu: |-
294
219
  {{recipient}}
295
220
  {{street}}
296
221
  {{zip}} {{city}}
297
222
  {{country}}
298
- mk:
299
- name: Macedonia
300
- format: |-
223
+ mk: |-
301
224
  {{recipient}}
302
225
  {{street}}
303
226
  {{city}} {{zip}}
304
227
  {{country}}
305
- mx:
306
- name: Mexico
307
- format: |-
228
+ mx: |-
308
229
  {{recipient}}
309
230
  {{street}}
310
231
  {{zip}} {{city}} {{state}}
311
232
  {{country}}
312
- nc:
313
- name: New Caledonia
314
- format: |-
233
+ nc: |-
315
234
  {{recipient}}
316
235
  {{street}}
317
236
  {{zip}} {{city}}
318
237
  {{country}}
319
- nl:
320
- name: Netherlands
321
- format: |-
238
+ nl: |-
322
239
  {{recipient}}
323
240
  {{street}}
324
241
  {{zip}} {{city}}
325
242
  {{country}}
326
- "no":
327
- name: Norway
328
- format: |-
243
+ "no": |-
329
244
  {{recipient}}
330
245
  {{street}}
331
246
  {{zip}} {{city}}
332
247
  {{country}}
333
- nz:
334
- name: New Zealand
335
- format: |-
248
+ nz: |-
336
249
  {{recipient}}
337
250
  {{street}}
338
251
  {{state}}
339
252
  {{city}} {{zip}}
340
253
  {{country}}
341
- om:
342
- name: Oman
343
- format: |-
254
+ om: |-
344
255
  {{recipient}}
345
256
  {{street}}
346
257
  {{zip}} {{city}}
347
258
  {{state}}
348
259
  {{country}}
349
- ph:
350
- name: Philippines
351
- format: |-
260
+ ph: |-
352
261
  {{recipient}}
353
262
  {{street}} {{state}}
354
263
  {{zip}} {{city}}
355
264
  {{country}}
356
- pl:
357
- name: Poland
358
- format: |-
265
+ pl: |-
359
266
  {{recipient}}
360
267
  {{street}}
361
268
  {{zip}} {{city}}
362
269
  {{state}}
363
270
  {{country}}
364
- pt:
365
- name: Portugal
366
- format: |-
271
+ pt: |-
367
272
  {{recipient}}
368
273
  {{street}}
369
274
  {{zip}} {{city}} {{state}}
370
275
  {{country}}
371
- qa:
372
- name: Qatar
373
- format: |-
276
+ qa: |-
374
277
  {{recipient}}
375
278
  {{street}}
376
279
  {{zip}} {{city}}
377
280
  {{country}}
378
- ro:
379
- name: Romania
380
- format: |-
281
+ ro: |-
381
282
  {{recipient}}
382
283
  {{street}}
383
284
  {{zip}} {{city}}
384
285
  {{country}}
385
- ru:
386
- name: Russian Federation
387
- format: |-
286
+ ru: |-
388
287
  {{recipient}}
389
288
  {{zip}} {{city}}
390
289
  {{street}}
391
290
  {{country}}
392
- sa:
393
- name: Saudi Arabia
394
- format: |-
291
+ sa: |-
395
292
  {{recipient}}
396
293
  {{street}}
397
294
  {{zip}} {{city}}
398
295
  {{country}}
399
- se:
400
- name: Sweden
401
- format: |-
296
+ se: |-
402
297
  {{recipient}}
403
298
  {{street}}
404
299
  {{zip}} {{city}}
405
300
  {{country}}
406
- sg:
407
- name: Singapore
408
- format: |-
301
+ sg: |-
409
302
  {{recipient}}
410
303
  {{street}}
411
304
  {{city}} {{zip}}
412
305
  {{country}}
413
- si:
414
- name: Slovenia
415
- format: |-
306
+ si: |-
416
307
  {{recipient}}
417
308
  {{street}}
418
309
  {{zip}} {{city}}
419
310
  {{country}}
420
- sk:
421
- name: Slovakia
422
- format: |-
311
+ sk: |-
423
312
  {{recipient}}
424
313
  {{street}}
425
314
  {{zip}} {{city}}
426
315
  {{country}}
427
- sy:
428
- name: Syrian Arab Republic
429
- format: |-
316
+ sy: |-
430
317
  {{recipient}}
431
318
  {{street}}
432
319
  {{zip}} {{city}}
433
320
  {{country}}
434
- th:
435
- name: Thailand
436
- format: |-
321
+ th: |-
437
322
  {{recipient}}
438
323
  {{street}}
439
324
  {{city}} {{state}} {{zip}}
440
325
  {{country}}
441
- tr:
442
- name: Turkey
443
- format: |-
326
+ tr: |-
444
327
  {{recipient}}
445
328
  {{street}}
446
329
  {{zip}} {{city}}
447
330
  {{country}}
448
- tw:
449
- name: Taiwan
450
- format: |-
331
+ tw: |-
451
332
  {{recipient}}
452
333
  {{street}}
453
334
  {{city}} {{state}} {{zip}}
454
335
  {{country}}
455
- ua:
456
- name: Ukraine
457
- format: |-
336
+ ua: |-
458
337
  {{recipient}}
459
338
  {{street}}
460
339
  {{city}} {{state}}
461
340
  {{zip}}
462
341
  {{country}}
463
- us:
464
- name: United States
465
- format: |-
342
+ us: |-
466
343
  {{recipient}}
467
344
  {{street}}
468
345
  {{city}} {{state}} {{zip}}
469
346
  {{country}}
470
- ye:
471
- name: Yemen
472
- format: |-
347
+ ye: |-
473
348
  {{recipient}}
474
349
  {{street}}
475
350
  {{zip}} {{city}}
476
351
  {{country}}
477
- yu:
478
- name: Serbia and Montenegro
479
- format: |-
352
+ yu: |-
480
353
  {{recipient}}
481
354
  {{street}}
482
355
  {{zip}} {{city}}
483
356
 
484
357
  {{state}}
485
358
  {{country}}
486
- za:
487
- name: South Africa
488
- format: |-
359
+ za: |-
489
360
  {{recipient}}
490
361
  {{street}}
491
362
  {{city}}
@@ -1,3 +1,4 @@
1
+ require 'biggs/format'
1
2
  require 'biggs/formatter'
2
3
  require 'yaml'
3
4
 
@@ -7,15 +8,13 @@ module Biggs
7
8
  @@formats ||= YAML.load_file(File.join(File.dirname(__FILE__), '..', 'formats.yml')) || {}
8
9
  end
9
10
 
10
- def enable_activerecord
11
- return if ActiveRecord::Base.respond_to? :biggs_formatter
12
- require 'biggs/activerecord'
13
- ActiveRecord::Base.send :include, Biggs::ActiveRecordAdapter
11
+ def country_names
12
+ @@country_names ||= YAML.load_file(File.join(File.dirname(__FILE__), '..', 'country_names.yml')) || {}
14
13
  end
15
14
  end
16
15
  end
17
16
 
18
- if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
19
- Biggs.enable_activerecord
20
- end
21
-
17
+ if defined?(ActiveRecord) and defined?(ActiveRecord::Base) and !ActiveRecord::Base.respond_to?(:biggs_formatter)
18
+ require 'biggs/activerecord'
19
+ ActiveRecord::Base.send :include, Biggs::ActiveRecordAdapter
20
+ end
@@ -0,0 +1,25 @@
1
+ module Biggs
2
+ class Format
3
+ attr_reader :country_name, :iso_code, :format_string
4
+
5
+ DEFAULT_WITH_STATE =
6
+
7
+ def initialize(iso_code)
8
+ @iso_code = iso_code.to_s.downcase
9
+ @country_name = Biggs.country_names[@iso_code]
10
+ @format_string = Biggs.formats[@iso_code]
11
+ end
12
+
13
+ class << self
14
+ def find(iso_code)
15
+ entries_cache[iso_code] ||= new(iso_code)
16
+ end
17
+
18
+ private
19
+
20
+ def entries_cache
21
+ @entries_cache ||= {}
22
+ end
23
+ end
24
+ end
25
+ end
@@ -7,35 +7,28 @@ module Biggs
7
7
  @blank_country_on = [options[:blank_country_on]].compact.flatten.map{|s| s.to_s.downcase}
8
8
  end
9
9
 
10
- def format(country_code, values={})
10
+ def format(iso_code, values={})
11
11
  values.symbolize_keys! if values.respond_to?(:symbolize_keys!)
12
- country_code = country_code.dup.to_s.downcase
13
-
14
- country_entry = (Biggs.formats[country_code] || default_country_entry(country_code, values))
15
- country_name = (country_entry["name"].dup || "").to_s
16
- country_format = (country_entry["format"].dup || "").to_s
17
-
12
+
13
+ format = Biggs::Format.find(iso_code)
14
+ format_string = (format.format_string || default_format_string(values[:state])).dup.to_s
15
+ country_name = blank_country_on.include?(format.iso_code) ? "" : format.country_name || format.iso_code
16
+
18
17
  (FIELDS - [:country]).each do |key|
19
- country_format.gsub!(/\{\{#{key}\}\}/, (values[key] || "").to_s)
18
+ format_string.gsub!(/\{\{#{key}\}\}/, (values[key] || "").to_s)
20
19
  end
21
-
22
- country_name = "" if blank_country_on.include?(country_code)
23
- country_format.gsub!(/\{\{country\}\}/, country_name)
24
-
25
- country_format.gsub(/\n$/,"")
20
+ format_string.gsub!(/\{\{country\}\}/, country_name)
21
+ format_string.gsub(/\n$/, "")
26
22
  end
27
23
 
28
24
  attr_accessor :blank_country_on, :default_country_without_state, :default_country_with_state
29
25
 
30
26
  private
31
-
32
- def default_country_entry(country_code, values={})
33
- {
34
- "name" => country_code.to_s,
35
- "format" => (values[:state] && values[:state] != "" ?
36
- Biggs.formats[default_country_with_state || "us"] :
37
- Biggs.formats[default_country_without_state || "fr"])["format"]
38
- }
27
+
28
+ def default_format_string(state)
29
+ state && state != "" ?
30
+ Biggs.formats[default_country_with_state || "us"] :
31
+ Biggs.formats[default_country_without_state || "fr"]
39
32
  end
40
33
  end
41
34
 
@@ -1,3 +1,3 @@
1
1
  module Biggs
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -106,7 +106,7 @@ describe "ActiveRecord Instance" do
106
106
  end
107
107
 
108
108
  it "should return postal_address on postal_address" do
109
- FooBar.new.postal_address.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States")
109
+ FooBar.new.postal_address.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States of America")
110
110
  end
111
111
  end
112
112
 
@@ -128,7 +128,7 @@ describe "ActiveRecord Instance" do
128
128
  end
129
129
 
130
130
  it "should return formatted address on my_postal_address_method" do
131
- FooBarCustomMethod.new.my_postal_address_method.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States")
131
+ FooBarCustomMethod.new.my_postal_address_method.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States of America")
132
132
  end
133
133
  end
134
134
 
@@ -140,7 +140,7 @@ describe "ActiveRecord Instance" do
140
140
 
141
141
  describe "Customized array of symbols" do
142
142
  it "should return formatted address with two lines for street" do
143
- FooBarCustomArray.new.postal_address.should eql("RECIPIENT\nAddress line 1\nAddress line 2\nCITY STATE ZIP\nUnited States")
143
+ FooBarCustomArray.new.postal_address.should eql("RECIPIENT\nAddress line 1\nAddress line 2\nCITY STATE ZIP\nUnited States of America")
144
144
  end
145
145
  end
146
146
 
@@ -8,7 +8,7 @@ describe Biggs::Formatter, "with defaults" do
8
8
  before { @biggs = Biggs::Formatter.new }
9
9
 
10
10
  it "should format to us format" do
11
- @biggs.format('us', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY STATE 12345\nUnited States")
11
+ @biggs.format('us', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY STATE 12345\nUnited States of America")
12
12
  end
13
13
 
14
14
  it "should format to de format" do
@@ -39,6 +39,14 @@ describe Biggs::Formatter, "with defaults" do
39
39
  @biggs.format('nc', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\n12345 CITY\nNew Caledonia")
40
40
  end
41
41
 
42
+ it "should use country name if Country is known but format not" do
43
+ @biggs.format('af', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nAfghanistan")
44
+ end
45
+
46
+ it "should use ISO Code if Country is unknown" do
47
+ @biggs.format('xx', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nxx")
48
+ end
49
+
42
50
  end
43
51
 
44
52
  describe Biggs, "with options" do
@@ -0,0 +1,32 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Biggs::Format do
4
+ describe ".find" do
5
+ context "known country with format" do
6
+ subject { Biggs::Format.find("cn") }
7
+
8
+ it{ should be_kind_of(Biggs::Format) }
9
+ its(:country_name){ should eql("China") }
10
+ its(:iso_code){ should eql("cn") }
11
+ its(:format_string){ should eql("{{recipient}}\n{{street}}\n{{zip}} {{city}} {{state}}\n{{country}}") }
12
+ end
13
+
14
+ context "known country with unknown format" do
15
+ subject { Biggs::Format.find("af") }
16
+
17
+ it{ should be_kind_of(Biggs::Format) }
18
+ its(:country_name){ should eql("Afghanistan") }
19
+ its(:iso_code){ should eql("af") }
20
+ its(:format_string){ should eql(nil) }
21
+ end
22
+
23
+ context "unknown country" do
24
+ subject { Biggs::Format.find("xx") }
25
+
26
+ it{ should be_kind_of(Biggs::Format) }
27
+ its(:country_name){ should eql(nil) }
28
+ its(:iso_code){ should eql("xx") }
29
+ its(:format_string){ should eql(nil) }
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 2
9
- version: 0.2.2
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sebastian Munz
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-02-06 00:00:00 +01:00
17
+ date: 2012-06-15 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -84,21 +84,24 @@ extra_rdoc_files: []
84
84
  files:
85
85
  - .gitignore
86
86
  - .rvmrc
87
- - CHANGES.textile
87
+ - CHANGES.md
88
88
  - Gemfile
89
89
  - LICENSE
90
- - README.textile
90
+ - README.md
91
91
  - Rakefile
92
92
  - biggs.gemspec
93
+ - country_names.yml
93
94
  - formats.yml
94
95
  - init.rb
95
96
  - lib/biggs.rb
96
97
  - lib/biggs/activerecord.rb
98
+ - lib/biggs/format.rb
97
99
  - lib/biggs/formatter.rb
98
100
  - lib/biggs/version.rb
99
101
  - spec/spec_helper.rb
100
102
  - spec/unit/activerecord_spec.rb
101
103
  - spec/unit/biggs_spec.rb
104
+ - spec/unit/format_spec.rb
102
105
  has_rdoc: true
103
106
  homepage: https://github.com/yolk/biggs
104
107
  licenses: []
@@ -135,3 +138,4 @@ test_files:
135
138
  - spec/spec_helper.rb
136
139
  - spec/unit/activerecord_spec.rb
137
140
  - spec/unit/biggs_spec.rb
141
+ - spec/unit/format_spec.rb