Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yolk/biggs
Browse files Browse the repository at this point in the history
  • Loading branch information
yolk committed Dec 1, 2023
2 parents cf03be7 + 4d7f2d9 commit e1749bb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 28 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

on: [push, pull_request]

jobs:
test:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
ruby: ["2.7", "3.0", "3.1", "3.2", ruby-head]

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true # 'bundle install' and cache gems
ruby-version: ${{ matrix.ruby }}
- name: Run tests
run: bundle exec rake
68 changes: 40 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ As a ruby gem:

### Standalone usage

f = Biggs::Formatter.new

f.format("de", # <= ISO alpha 2 code
:recipient => "Yolk Sebastian Munz & Julia Soergel GbR",
:street => "Musterallee 12", # <= street + house number
:city => "Ausgedacht",
:zip => 12345,
:state => "Nowhere" # <= state/province/region
)
```ruby
f = Biggs::Formatter.new

f.format("de", # <= ISO alpha 2 code
:recipient => "Yolk Sebastian Munz & Julia Soergel GbR",
:street => "Musterallee 12", # <= street + house number
:city => "Ausgedacht",
:zip => 12345,
:state => "Nowhere" # <= state/province/region
)
```

returns

Expand All @@ -29,7 +31,9 @@ At the moment Biggs::Formatter.new accepts only one option:

*blank_country_on* ISO alpha 2 code (single string or array) of countries the formatter should skip the line "country" (for national shipping).

Biggs::Formatter.new(blank_country_on: "de")
```ruby
Biggs::Formatter.new(blank_country_on: "de")
```

With the data from the above example this would return:

Expand All @@ -39,41 +43,49 @@ With the data from the above example this would return:

### Usage with Class

class Address
include Biggs
```ruby
class Address
include Biggs

biggs :postal_address
end
biggs :postal_address
end
```

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').

You can customize the method-names biggs will use by passing in a hash of options:

class Address
include Biggs
```ruby
class Address
include Biggs

biggs :postal_address,
:zip => :postal_code,
:country => :country_code,
:street => Proc.new {|address| "#{address.street} #{address.house_number}" }
end
biggs :postal_address,
:zip => :postal_code,
:country => :country_code,
:street => Proc.new {|address| "#{address.street} #{address.house_number}" }
end
```

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.

You can even pass in a array of symbols:

class Address
include Biggs
```ruby
class Address
include Biggs

biggs :postal_address,
:recipient => [:company_name, :person_name]
end
biggs :postal_address,
:recipient => [:company_name, :person_name]
end
```

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.

To access the formatted address string, simply call the provided method on an address instance:

Address.new.postal_address
```ruby
Address.new.postal_address
```

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.

Expand Down Expand Up @@ -149,4 +161,4 @@ biggs knows how to format addresses of over 60 different countries. If you are m

biggs is tested to behave well with ActiveSupport 3 to 7

Copyright (c) 2009-2023 Yolk Sebastian Munz & Julia Soergel GbR
Copyright (c) 2009-2023 mite GmbH
2 changes: 2 additions & 0 deletions country_names.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ co: Colombia
cr: Costa Rica
cu: Cuba
cv: Cape Verde
cw: Curaçao
cx: Christmas Island
cy: Cyprus
cz: Czech Republic
Expand Down Expand Up @@ -239,6 +240,7 @@ vn: Vietnam
vu: Vanuatu
wf: Wallis and Futuna
ws: Samoa
xk: Kosovo
ye: Yemen
yt: Mayotte
za: South Africa
Expand Down
10 changes: 10 additions & 0 deletions formats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ cn: |-
{{street}}
{{zip}} {{city}} {{state}}
{{country}}
cw: |-
{{recipient}}
{{street}}
{{zip}} {{city}}
{{country}}
cz: |-
{{recipient}}
{{street}}
Expand Down Expand Up @@ -343,6 +348,11 @@ us: |-
{{street}}
{{city}} {{state}} {{zip}}
{{country}}
xk: |-
{{recipient}}
{{street}}
{{zip}} {{city}}
{{country}}
ye: |-
{{recipient}}
{{street}}
Expand Down

0 comments on commit e1749bb

Please sign in to comment.