biggs 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +23 -0
- data/CHANGES.md +4 -0
- data/README.md +40 -28
- data/country_names.yml +2 -0
- data/formats.yml +10 -0
- data/lib/biggs/formatter.rb +2 -0
- data/lib/biggs/version.rb +1 -1
- data/lib/biggs.rb +1 -0
- data/spec/unit/biggs_spec.rb +34 -21
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7aa8d5152785fa038f6bffa57fce153cbf2c2a9f11b7c65723bf8fbb75d9688e
|
4
|
+
data.tar.gz: c0010a02600e417e3a90d9799a1bec898fe015ef8aa10b0d6f1c6471e9b288a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b74223bcdb43f5c8133c8bdeaa94332f0919569be4204e0d635781759e6c26027f2a2f365b389deb2a9b384c6c4f3b1c619551e1aa116918fef823905b3656fe
|
7
|
+
data.tar.gz: 1a9c63cca3fa960dfa0205065e4bf541c934b03b42e516a04b1724600ce3f6bf72231477994c21a690cee727fcba05458c4c99f7e5f666847bef207f314338e0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby: ["2.7", "3.0", "3.1", "3.2", ruby-head]
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
bundler-cache: true # 'bundle install' and cache gems
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rake
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -8,15 +8,17 @@ As a ruby gem:
|
|
8
8
|
|
9
9
|
### Standalone usage
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
```ruby
|
12
|
+
f = Biggs::Formatter.new
|
13
|
+
|
14
|
+
f.format("de", # <= ISO alpha 2 code
|
15
|
+
:recipient => "Yolk Sebastian Munz & Julia Soergel GbR",
|
16
|
+
:street => "Musterallee 12", # <= street + house number
|
17
|
+
:city => "Ausgedacht",
|
18
|
+
:zip => 12345,
|
19
|
+
:state => "Nowhere" # <= state/province/region
|
20
|
+
)
|
21
|
+
```
|
20
22
|
|
21
23
|
returns
|
22
24
|
|
@@ -29,7 +31,9 @@ At the moment Biggs::Formatter.new accepts only one option:
|
|
29
31
|
|
30
32
|
*blank_country_on* ISO alpha 2 code (single string or array) of countries the formatter should skip the line "country" (for national shipping).
|
31
33
|
|
32
|
-
|
34
|
+
```ruby
|
35
|
+
Biggs::Formatter.new(blank_country_on: "de")
|
36
|
+
```
|
33
37
|
|
34
38
|
With the data from the above example this would return:
|
35
39
|
|
@@ -39,41 +43,49 @@ With the data from the above example this would return:
|
|
39
43
|
|
40
44
|
### Usage with Class
|
41
45
|
|
42
|
-
|
43
|
-
|
46
|
+
```ruby
|
47
|
+
class Address
|
48
|
+
include Biggs
|
44
49
|
|
45
|
-
|
46
|
-
|
50
|
+
biggs :postal_address
|
51
|
+
end
|
52
|
+
```
|
47
53
|
|
48
54
|
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').
|
49
55
|
|
50
56
|
You can customize the method-names biggs will use by passing in a hash of options:
|
51
57
|
|
52
|
-
|
53
|
-
|
58
|
+
```ruby
|
59
|
+
class Address
|
60
|
+
include Biggs
|
54
61
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
62
|
+
biggs :postal_address,
|
63
|
+
:zip => :postal_code,
|
64
|
+
:country => :country_code,
|
65
|
+
:street => Proc.new {|address| "#{address.street} #{address.house_number}" }
|
66
|
+
end
|
67
|
+
```
|
60
68
|
|
61
69
|
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
70
|
|
63
71
|
You can even pass in a array of symbols:
|
64
72
|
|
65
|
-
|
66
|
-
|
73
|
+
```ruby
|
74
|
+
class Address
|
75
|
+
include Biggs
|
67
76
|
|
68
|
-
|
69
|
-
|
70
|
-
|
77
|
+
biggs :postal_address,
|
78
|
+
:recipient => [:company_name, :person_name]
|
79
|
+
end
|
80
|
+
```
|
71
81
|
|
72
82
|
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.
|
73
83
|
|
74
84
|
To access the formatted address string, simply call the provided method on an address instance:
|
75
85
|
|
76
|
-
|
86
|
+
```ruby
|
87
|
+
Address.new.postal_address
|
88
|
+
```
|
77
89
|
|
78
90
|
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.
|
79
91
|
|
@@ -149,4 +161,4 @@ biggs knows how to format addresses of over 60 different countries. If you are m
|
|
149
161
|
|
150
162
|
biggs is tested to behave well with ActiveSupport 3 to 7
|
151
163
|
|
152
|
-
Copyright (c) 2009-
|
164
|
+
Copyright (c) 2009-2023 mite GmbH
|
data/country_names.yml
CHANGED
@@ -50,6 +50,7 @@ co: Colombia
|
|
50
50
|
cr: Costa Rica
|
51
51
|
cu: Cuba
|
52
52
|
cv: Cape Verde
|
53
|
+
cw: Curaçao
|
53
54
|
cx: Christmas Island
|
54
55
|
cy: Cyprus
|
55
56
|
cz: Czech Republic
|
@@ -239,6 +240,7 @@ vn: Vietnam
|
|
239
240
|
vu: Vanuatu
|
240
241
|
wf: Wallis and Futuna
|
241
242
|
ws: Samoa
|
243
|
+
xk: Kosovo
|
242
244
|
ye: Yemen
|
243
245
|
yt: Mayotte
|
244
246
|
za: South Africa
|
data/formats.yml
CHANGED
@@ -68,6 +68,11 @@ cn: |-
|
|
68
68
|
{{street}}
|
69
69
|
{{zip}} {{city}} {{state}}
|
70
70
|
{{country}}
|
71
|
+
cw: |-
|
72
|
+
{{recipient}}
|
73
|
+
{{street}}
|
74
|
+
{{zip}} {{city}}
|
75
|
+
{{country}}
|
71
76
|
cz: |-
|
72
77
|
{{recipient}}
|
73
78
|
{{street}}
|
@@ -343,6 +348,11 @@ us: |-
|
|
343
348
|
{{street}}
|
344
349
|
{{city}} {{state}} {{zip}}
|
345
350
|
{{country}}
|
351
|
+
xk: |-
|
352
|
+
{{recipient}}
|
353
|
+
{{street}}
|
354
|
+
{{zip}} {{city}}
|
355
|
+
{{country}}
|
346
356
|
ye: |-
|
347
357
|
{{recipient}}
|
348
358
|
{{street}}
|
data/lib/biggs/formatter.rb
CHANGED
@@ -6,6 +6,7 @@ module Biggs
|
|
6
6
|
|
7
7
|
def initialize(options={})
|
8
8
|
@blank_country_on = [options[:blank_country_on]].compact.flatten.map{|s| s.to_s.downcase}
|
9
|
+
@remove_empty_lines = !!options[:remove_empty_lines]
|
9
10
|
end
|
10
11
|
|
11
12
|
def format(iso_code, values={})
|
@@ -19,6 +20,7 @@ module Biggs
|
|
19
20
|
format_string.gsub!(/\{\{#{key}\}\}/, (values[key] || "").to_s)
|
20
21
|
end
|
21
22
|
format_string.gsub!(/\{\{country\}\}/, country_name)
|
23
|
+
format_string.gsub!(/\n(\s+)?\n/, "\n") if @remove_empty_lines
|
22
24
|
format_string.strip
|
23
25
|
end
|
24
26
|
|
data/lib/biggs/version.rb
CHANGED
data/lib/biggs.rb
CHANGED
data/spec/unit/biggs_spec.rb
CHANGED
@@ -4,33 +4,33 @@ FAKE_ATTR_WITH_STATE = {:state => "STATE", :city => "CITY", :zip => 12345, :stre
|
|
4
4
|
FAKE_ATTR_WO_STATE = {:city => "CITY", :zip => 12345, :street => "STREET", :recipient => "MR. X"}
|
5
5
|
|
6
6
|
describe Biggs::Formatter, "with defaults" do
|
7
|
-
|
7
|
+
|
8
8
|
before { @biggs = Biggs::Formatter.new }
|
9
|
-
|
9
|
+
|
10
10
|
it "should format to us format" do
|
11
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
|
15
15
|
@biggs.format('de', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\n12345 CITY\nGermany")
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should format to british format" do
|
19
19
|
@biggs.format('gb', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY\nSTATE\n12345\nUnited Kingdom")
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "should format to fr format" do
|
23
23
|
@biggs.format('fr', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nFrance")
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should format to fr format if country_code unknown and there is no STATE given" do
|
27
27
|
@biggs.format('unknown', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nunknown")
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should format to us format if country_code unknown and there is no STATE given" do
|
31
31
|
@biggs.format('unknown', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY STATE 12345\nunknown")
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should format to no(rwegian) format" do
|
35
35
|
@biggs.format('no', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\n12345 CITY\nNorway")
|
36
36
|
end
|
@@ -38,43 +38,56 @@ describe Biggs::Formatter, "with defaults" do
|
|
38
38
|
it "should format to NC format" 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
42
|
it "should use country name if Country is known but format not" do
|
43
43
|
@biggs.format('af', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nAfghanistan")
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should use ISO Code if Country is unknown" do
|
47
47
|
@biggs.format('xx', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nxx")
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
end
|
51
51
|
|
52
52
|
describe Biggs, "with options" do
|
53
|
-
|
53
|
+
|
54
54
|
describe "blank_country_on de" do
|
55
55
|
before { @biggs = Biggs::Formatter.new(:blank_country_on => 'de') }
|
56
|
-
|
56
|
+
|
57
57
|
it "should have blank country in 'de' address" do
|
58
58
|
@biggs.format('de', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY")
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "should have country in 'fr' address" do
|
62
62
|
@biggs.format('fr', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\n12345 CITY\nFrance")
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
describe "blank_country_on multiple (US,de)" do
|
68
68
|
before { @biggs = Biggs::Formatter.new(:blank_country_on => ['US', "de"]) }
|
69
|
-
|
69
|
+
|
70
70
|
it "should have blank country in 'us' address" do
|
71
71
|
@biggs.format('us', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY STATE 12345")
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
it "should have country in 'fr' address" do
|
75
75
|
@biggs.format('fr', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\n12345 CITY\nFrance")
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "remove_empty_lines" do
|
81
|
+
before { @biggs = Biggs::Formatter.new(:remove_empty_lines => true) }
|
82
|
+
|
83
|
+
|
84
|
+
it "should remove empty lines" do
|
85
|
+
@biggs.format('gb', FAKE_ATTR_WO_STATE).should eql("MR. X\nSTREET\nCITY\n12345\nUnited Kingdom")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should format normally without empty lines" do
|
89
|
+
@biggs.format('gb', FAKE_ATTR_WITH_STATE).should eql("MR. X\nSTREET\nCITY\nSTATE\n12345\nUnited Kingdom")
|
90
|
+
end
|
91
|
+
|
78
92
|
end
|
79
|
-
|
80
|
-
end
|
93
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biggs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Munz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -88,6 +88,7 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".github/workflows/ci.yml"
|
91
92
|
- ".gitignore"
|
92
93
|
- ".rvmrc"
|
93
94
|
- CHANGES.md
|
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
128
|
- !ruby/object:Gem::Version
|
128
129
|
version: '0'
|
129
130
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
131
|
+
rubygems_version: 3.3.7
|
131
132
|
signing_key:
|
132
133
|
specification_version: 4
|
133
134
|
summary: biggs is a small ruby gem/rails plugin for formatting postal addresses from
|