biggs 0.3.3 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGES.md +17 -0
- data/README.md +19 -17
- data/biggs.gemspec +3 -2
- data/lib/biggs/concern.rb +34 -0
- data/lib/biggs/extractor.rb +36 -0
- data/lib/biggs/format.rb +3 -3
- data/lib/biggs/formatter.rb +13 -12
- data/lib/biggs/version.rb +2 -2
- data/lib/biggs.rb +9 -13
- data/spec/spec_helper.rb +4 -9
- data/spec/unit/{activerecord_spec.rb → concern_spec.rb} +57 -41
- metadata +51 -47
- data/lib/biggs/activerecord.rb +0 -68
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b305ad58e72593f21215121377ae70f2d17bd29a2d61f3265230f44c9e0c3092
|
4
|
+
data.tar.gz: 34566de6851e95ebc713110a6822498fa9da24c5fed7e158a7f53676ce11ce51
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34c29129d47a847e79e81793724f57a06ad89955004f240f154c491cb5bb7a35c68d49d7af52e9c66c609fae7335c5b2d7733f515287d7f7f68145e86665c845
|
7
|
+
data.tar.gz: 577f6f7d55229a2f5c3e6a9b0b4d5dd5badb488551da4ec6eadf8189ac6dd1ab4ab9ef56e176c2308fd9dd7eff29db9a8698157279a1cb4976e814bb7053e4f8
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
+
### 0.5.1 / 2022-04-08
|
4
|
+
|
5
|
+
* Biggs::Extractor: small refactorings + don't delete options
|
6
|
+
|
7
|
+
### 0.5.0 / 2022-04-08
|
8
|
+
|
9
|
+
* Refactored Biggs::Concern to use Biggs::Extractor
|
10
|
+
* Removed activerecord dependency and use only activesupport instead
|
11
|
+
* Renamed Biggs::ActiveRecordAdapter to Biggs::Concern, include with 'include Biggs'
|
12
|
+
* Optimization: Added Biggs::Formatter::FIELDS_WO_COUNTRY
|
13
|
+
* Moved Biggs.formats and Biggs.country_names to Constants Biggs::FORMATS & Biggs::COUNTRY_NAMES
|
14
|
+
|
15
|
+
### 0.4.0 / 2022-04-08
|
16
|
+
|
17
|
+
* [BREAKING]: Do not include to ActiveRecord::Base per default, use 'include Biggs::ActiveRecordAdapter' in your classes
|
18
|
+
* Allow multiple biggs methods per class
|
19
|
+
|
3
20
|
### 0.3.3 / 2013-05-06
|
4
21
|
|
5
22
|
* Added support for Rails 4 (by [mdemare](https://github.com/mdemare))
|
data/README.md
CHANGED
@@ -4,11 +4,7 @@ biggs is a small ruby gem/rails plugin for formatting postal addresses from over
|
|
4
4
|
|
5
5
|
As a ruby gem:
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
If your rather prefer to install it as a plugin for rails, from your application directory simply run:
|
10
|
-
|
11
|
-
script/plugin install git://github.com/yolk/biggs.git
|
7
|
+
gem install biggs
|
12
8
|
|
13
9
|
### Standalone usage
|
14
10
|
|
@@ -16,34 +12,36 @@ If your rather prefer to install it as a plugin for rails, from your application
|
|
16
12
|
|
17
13
|
f.format("de", # <= ISO alpha 2 code
|
18
14
|
:recipient => "Yolk Sebastian Munz & Julia Soergel GbR",
|
19
|
-
:street => "
|
20
|
-
:city => "
|
21
|
-
:zip =>
|
22
|
-
:state => "
|
15
|
+
:street => "Musterallee 12", # <= street + house number
|
16
|
+
:city => "Ausgedacht",
|
17
|
+
:zip => 12345,
|
18
|
+
:state => "Nowhere" # <= state/province/region
|
23
19
|
)
|
24
20
|
|
25
21
|
returns
|
26
22
|
|
27
23
|
"Yolk Sebastian Munz & Julia Soergel GbR
|
28
|
-
|
29
|
-
|
24
|
+
Musterallee 12
|
25
|
+
12345 Ausgedacht
|
30
26
|
Germany"
|
31
27
|
|
32
28
|
At the moment Biggs::Formatter.new accepts only one option:
|
33
29
|
|
34
|
-
*
|
30
|
+
*blank_country_on* ISO alpha 2 code (single string or array) of countries the formatter should skip the line "country" (for national shipping).
|
35
31
|
|
36
|
-
Biggs::Formatter.new(:
|
32
|
+
Biggs::Formatter.new(blank_country_on: "de")
|
37
33
|
|
38
34
|
With the data from the above example this would return:
|
39
35
|
|
40
36
|
"Yolk Sebastian Munz & Julia Soergel GbR
|
41
|
-
|
42
|
-
|
37
|
+
Musterallee 12
|
38
|
+
12345 Ausgedacht"
|
43
39
|
|
44
40
|
### Usage with Rails and ActiveRecord
|
45
41
|
|
46
42
|
Address < ActiveRecord::Base
|
43
|
+
include Biggs
|
44
|
+
|
47
45
|
biggs :postal_address
|
48
46
|
end
|
49
47
|
|
@@ -52,6 +50,8 @@ This adds the method postal_address to your Address-model, and assumes the prese
|
|
52
50
|
You can customize the method-names biggs will use by passing in a hash of options:
|
53
51
|
|
54
52
|
Address < ActiveRecord::Base
|
53
|
+
include Biggs
|
54
|
+
|
55
55
|
biggs :postal_address,
|
56
56
|
:zip => :postal_code,
|
57
57
|
:country => :country_code,
|
@@ -63,6 +63,8 @@ You can pass in a symbol to let biggs call a different method on your Address-mo
|
|
63
63
|
You can even pass in a array of symbols:
|
64
64
|
|
65
65
|
Address < ActiveRecord::Base
|
66
|
+
include Biggs
|
67
|
+
|
66
68
|
biggs :postal_address,
|
67
69
|
:recipient => [:company_name, :person_name]
|
68
70
|
end
|
@@ -145,6 +147,6 @@ biggs knows how to format addresses of over 60 different countries. If you are m
|
|
145
147
|
* United States of America
|
146
148
|
* Yemen
|
147
149
|
|
148
|
-
biggs is tested to behave well with
|
150
|
+
biggs is tested to behave well with ActiveSupport 3 to 7
|
149
151
|
|
150
|
-
Copyright (c) 2009-
|
152
|
+
Copyright (c) 2009-2022 Yolk Sebastian Munz & Julia Soergel GbR
|
data/biggs.gemspec
CHANGED
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_dependency '
|
22
|
+
s.add_dependency 'activesupport', '>= 3.0'
|
23
23
|
s.add_development_dependency 'rake'
|
24
|
-
s.add_development_dependency 'rspec', '>=
|
24
|
+
s.add_development_dependency 'rspec', '>= 3.0'
|
25
|
+
s.add_development_dependency 'rspec-its'
|
25
26
|
s.add_development_dependency 'sqlite3', '>= 1.3.5'
|
26
27
|
end
|
27
28
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/class/attribute'
|
3
|
+
require 'biggs/extractor'
|
4
|
+
require 'biggs/formatter'
|
5
|
+
|
6
|
+
module Biggs
|
7
|
+
module Concern
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
included do
|
11
|
+
class_attribute :biggs_config, default: {}
|
12
|
+
end
|
13
|
+
|
14
|
+
class_methods do
|
15
|
+
def biggs(method_name=:postal_address, options={})
|
16
|
+
self.define_method(method_name) do
|
17
|
+
formatter = self.biggs_config[method_name][:formatter]
|
18
|
+
extractor = self.biggs_config[method_name][:extractor]
|
19
|
+
formatter.format(
|
20
|
+
extractor.get_value(self, :country),
|
21
|
+
extractor.get_values(self)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
self.biggs_config = self.biggs_config.dup
|
26
|
+
|
27
|
+
self.biggs_config[method_name] = {
|
28
|
+
formatter: Biggs::Formatter.new(options),
|
29
|
+
extractor: Biggs::Extractor.new(options)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Biggs
|
2
|
+
class Extractor
|
3
|
+
def initialize(options)
|
4
|
+
@value_methods = Biggs::Formatter::FIELDS.reduce({}) do |methods, field|
|
5
|
+
methods[field] = options[field] if options[field]
|
6
|
+
methods
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_values(instance)
|
11
|
+
Biggs::Formatter::FIELDS_WO_COUNTRY.inject({}) do |values, field|
|
12
|
+
values[field] = get_value(instance, field)
|
13
|
+
values
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_value(instance, field)
|
18
|
+
key = @value_methods[field] || field
|
19
|
+
|
20
|
+
case key
|
21
|
+
when Symbol
|
22
|
+
instance.send(key.to_sym)
|
23
|
+
when Proc
|
24
|
+
key.call(instance).to_s
|
25
|
+
when Array
|
26
|
+
if key.all?{|it| it.is_a?(Symbol) }
|
27
|
+
key.map{|method| instance.send(method) }.reject(&:blank?).join("\n")
|
28
|
+
else
|
29
|
+
raise "Biggs: Can't handle #{field} type Array with non-symbolic entries"
|
30
|
+
end
|
31
|
+
else
|
32
|
+
raise "Biggs: Can't handle #{field} type #{key.class}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/biggs/format.rb
CHANGED
@@ -4,8 +4,8 @@ module Biggs
|
|
4
4
|
|
5
5
|
def initialize(iso_code)
|
6
6
|
@iso_code = iso_code.to_s.downcase
|
7
|
-
@country_name = Biggs
|
8
|
-
@format_string = Biggs
|
7
|
+
@country_name = Biggs::COUNTRY_NAMES[@iso_code]
|
8
|
+
@format_string = Biggs::FORMATS[@iso_code]
|
9
9
|
end
|
10
10
|
|
11
11
|
class << self
|
@@ -20,4 +20,4 @@ module Biggs
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
data/lib/biggs/formatter.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
module Biggs
|
2
2
|
class Formatter
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
|
4
|
+
FIELDS_WO_COUNTRY = [:recipient, :street, :city, :state, :zip].freeze
|
5
|
+
FIELDS = (FIELDS_WO_COUNTRY + [:country]).freeze
|
6
|
+
|
6
7
|
def initialize(options={})
|
7
8
|
@blank_country_on = [options[:blank_country_on]].compact.flatten.map{|s| s.to_s.downcase}
|
8
9
|
end
|
9
|
-
|
10
|
+
|
10
11
|
def format(iso_code, values={})
|
11
12
|
values.symbolize_keys! if values.respond_to?(:symbolize_keys!)
|
12
13
|
|
@@ -14,22 +15,22 @@ module Biggs
|
|
14
15
|
format_string = (format.format_string || default_format_string(values[:state])).dup.to_s
|
15
16
|
country_name = blank_country_on.include?(format.iso_code) ? "" : format.country_name || format.iso_code
|
16
17
|
|
17
|
-
|
18
|
+
FIELDS_WO_COUNTRY.each do |key|
|
18
19
|
format_string.gsub!(/\{\{#{key}\}\}/, (values[key] || "").to_s)
|
19
20
|
end
|
20
21
|
format_string.gsub!(/\{\{country\}\}/, country_name)
|
21
22
|
format_string.gsub(/\n$/, "")
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
attr_accessor :blank_country_on, :default_country_without_state, :default_country_with_state
|
25
|
-
|
26
|
+
|
26
27
|
private
|
27
|
-
|
28
|
+
|
28
29
|
def default_format_string(state)
|
29
30
|
state && state != "" ?
|
30
|
-
Biggs
|
31
|
-
Biggs
|
31
|
+
Biggs::FORMATS[default_country_with_state || "us"] :
|
32
|
+
Biggs::FORMATS[default_country_without_state || "fr"]
|
32
33
|
end
|
33
34
|
end
|
34
|
-
|
35
|
-
end
|
35
|
+
|
36
|
+
end
|
data/lib/biggs/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Biggs
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.5.1"
|
3
|
+
end
|
data/lib/biggs.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
|
+
require 'active_support'
|
1
2
|
require 'biggs/format'
|
2
3
|
require 'biggs/formatter'
|
4
|
+
require 'biggs/concern'
|
3
5
|
require 'yaml'
|
4
6
|
|
5
7
|
module Biggs
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
8
|
+
FORMATS = (YAML.load_file(File.join(File.dirname(__FILE__), '..', 'formats.yml')) || {}).freeze
|
9
|
+
COUNTRY_NAMES = (YAML.load_file(File.join(File.dirname(__FILE__), '..', 'country_names.yml')) || {}).freeze
|
10
|
+
|
11
|
+
extend ActiveSupport::Concern
|
12
|
+
|
13
|
+
included do
|
14
|
+
include Biggs::Concern
|
14
15
|
end
|
15
16
|
end
|
16
|
-
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
require 'rubygems'
|
3
3
|
require 'rspec'
|
4
|
+
require 'rspec/its'
|
4
5
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'biggs')
|
5
6
|
require 'logger'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
ActiveRecord::Schema.define do
|
12
|
-
create_table :base_tables, :force => true do |table|
|
13
|
-
table.string :name
|
14
|
-
end
|
15
|
-
end
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
10
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'active_record'
|
3
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
4
2
|
|
5
|
-
class
|
3
|
+
class BaseClass
|
4
|
+
include Biggs
|
5
|
+
|
6
6
|
Biggs::Formatter::FIELDS.each do |field|
|
7
7
|
define_method(field) do
|
8
8
|
field == :country ? "us" : field.to_s.upcase
|
@@ -10,101 +10,106 @@ class BaseTable < ActiveRecord::Base
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
class FooBarEmpty <
|
13
|
+
class FooBarEmpty < BaseClass;end
|
14
14
|
|
15
|
-
class FooBar <
|
15
|
+
class FooBar < BaseClass
|
16
16
|
biggs :postal_address
|
17
17
|
end
|
18
18
|
|
19
|
-
class FooBarCustomFields <
|
19
|
+
class FooBarCustomFields < BaseClass
|
20
20
|
biggs :postal_address, :country => :my_custom_country_method,
|
21
21
|
:city => :my_custom_city_method
|
22
|
-
|
22
|
+
|
23
23
|
def my_custom_country_method
|
24
24
|
"de"
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def my_custom_city_method
|
28
28
|
"Hamburg"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
class FooBarCustomBlankDECountry <
|
32
|
+
class FooBarCustomBlankDECountry < BaseClass
|
33
33
|
biggs :postal_address, :blank_country_on => "de"
|
34
|
-
|
34
|
+
|
35
35
|
def country
|
36
36
|
"DE"
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
class FooBarCustomMethod <
|
40
|
+
class FooBarCustomMethod < BaseClass
|
41
41
|
biggs :my_postal_address_method
|
42
42
|
end
|
43
43
|
|
44
|
-
class FooBarCustomProc <
|
45
|
-
biggs :postal_address,
|
46
|
-
:country => Proc.new {|it| it.method_accessed_from_proc + "XX"},
|
44
|
+
class FooBarCustomProc < BaseClass
|
45
|
+
biggs :postal_address,
|
46
|
+
:country => Proc.new {|it| it.method_accessed_from_proc + "XX"},
|
47
47
|
:state => Proc.new {|it| it.state.downcase }
|
48
|
-
|
48
|
+
|
49
49
|
def method_accessed_from_proc
|
50
50
|
"DE"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
class FooBarCustomArray <
|
55
|
-
biggs :postal_address,
|
54
|
+
class FooBarCustomArray < BaseClass
|
55
|
+
biggs :postal_address,
|
56
56
|
:street => [:address_1, :address_empty, :address_nil, :address_2]
|
57
|
-
|
57
|
+
|
58
58
|
def address_1
|
59
59
|
"Address line 1"
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def address_2
|
63
63
|
"Address line 2"
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def address_empty
|
67
67
|
""
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def address_nil
|
71
71
|
nil
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
class FooBarMultiple < BaseClass
|
76
|
+
biggs :postal_address_one
|
77
|
+
biggs :postal_address_two,
|
78
|
+
country: :alt_country
|
79
|
+
|
80
|
+
def alt_country
|
81
|
+
"Alt country"
|
79
82
|
end
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "ActiveRecord Class" do
|
86
|
+
|
87
|
+
it "should include Biggs::Concern" do
|
88
|
+
FooBar.included_modules.should be_include(Biggs::Concern)
|
84
89
|
end
|
85
|
-
|
86
|
-
it "should set class value
|
87
|
-
FooBar.class_eval("
|
90
|
+
|
91
|
+
it "should set class value biggs_config" do
|
92
|
+
FooBar.class_eval("biggs_config").should be_is_a(Hash)
|
88
93
|
end
|
89
|
-
|
94
|
+
|
90
95
|
it "should respond to biggs" do
|
91
96
|
FooBar.should be_respond_to(:biggs)
|
92
97
|
end
|
93
98
|
end
|
94
99
|
|
95
100
|
describe "ActiveRecord Instance" do
|
96
|
-
|
101
|
+
|
97
102
|
describe "Empty" do
|
98
103
|
it "should not have postal_address method" do
|
99
104
|
FooBarEmpty.new.should_not be_respond_to(:postal_address)
|
100
105
|
end
|
101
106
|
end
|
102
|
-
|
107
|
+
|
103
108
|
describe "Standard" do
|
104
109
|
it "should have postal_address method" do
|
105
110
|
FooBar.new.should be_respond_to(:postal_address)
|
106
111
|
end
|
107
|
-
|
112
|
+
|
108
113
|
it "should return postal_address on postal_address" do
|
109
114
|
FooBar.new.postal_address.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States of America")
|
110
115
|
end
|
@@ -121,27 +126,38 @@ describe "ActiveRecord Instance" do
|
|
121
126
|
FooBarCustomBlankDECountry.new.postal_address.should eql("RECIPIENT\nSTREET\nZIP CITY")
|
122
127
|
end
|
123
128
|
end
|
124
|
-
|
129
|
+
|
125
130
|
describe "Customized Method name" do
|
126
131
|
it "should have my_postal_address_method" do
|
127
132
|
FooBarCustomMethod.new.should be_respond_to(:my_postal_address_method)
|
128
133
|
end
|
129
|
-
|
134
|
+
|
130
135
|
it "should return formatted address on my_postal_address_method" do
|
131
136
|
FooBarCustomMethod.new.my_postal_address_method.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States of America")
|
132
137
|
end
|
133
138
|
end
|
134
|
-
|
139
|
+
|
135
140
|
describe "Customized Proc as Param" do
|
136
141
|
it "should return formatted address for unknown-country DEXX" do
|
137
142
|
FooBarCustomProc.new.postal_address.should eql("RECIPIENT\nSTREET\nCITY state ZIP\ndexx")
|
138
143
|
end
|
139
144
|
end
|
140
|
-
|
145
|
+
|
141
146
|
describe "Customized array of symbols" do
|
142
147
|
it "should return formatted address with two lines for street" do
|
143
148
|
FooBarCustomArray.new.postal_address.should eql("RECIPIENT\nAddress line 1\nAddress line 2\nCITY STATE ZIP\nUnited States of America")
|
144
149
|
end
|
145
150
|
end
|
146
151
|
|
147
|
-
|
152
|
+
describe "Multiple" do
|
153
|
+
|
154
|
+
it "should return postal_address on postal_address_one" do
|
155
|
+
FooBarMultiple.new.postal_address_one.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nUnited States of America")
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should return postal_address with alt country on postal_address_two" do
|
159
|
+
FooBarMultiple.new.postal_address_two.should eql("RECIPIENT\nSTREET\nCITY STATE ZIP\nalt country")
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
metadata
CHANGED
@@ -1,80 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: biggs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 0.3.3
|
4
|
+
version: 0.5.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Sebastian Munz
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-04-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
-
none: false
|
21
|
-
name: activerecord
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
23
|
requirements:
|
26
|
-
- -
|
24
|
+
- - ">="
|
27
25
|
- !ruby/object:Gem::Version
|
28
26
|
version: '3.0'
|
29
|
-
none: false
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
|
-
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
32
30
|
requirements:
|
33
|
-
- -
|
31
|
+
- - ">="
|
34
32
|
- !ruby/object:Gem::Version
|
35
33
|
version: '0'
|
36
|
-
none: false
|
37
|
-
name: rake
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
37
|
requirements:
|
42
|
-
- -
|
38
|
+
- - ">="
|
43
39
|
- !ruby/object:Gem::Version
|
44
40
|
version: '0'
|
45
|
-
none: false
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
|
-
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
48
44
|
requirements:
|
49
|
-
- -
|
45
|
+
- - ">="
|
50
46
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
52
|
-
none: false
|
53
|
-
name: rspec
|
47
|
+
version: '3.0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
51
|
requirements:
|
58
|
-
- -
|
52
|
+
- - ">="
|
59
53
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
none: false
|
54
|
+
version: '3.0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
63
64
|
version_requirements: !ruby/object:Gem::Requirement
|
64
65
|
requirements:
|
65
|
-
- -
|
66
|
+
- - ">="
|
66
67
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
68
|
-
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
69
70
|
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.3.5
|
70
76
|
type: :development
|
71
77
|
prerelease: false
|
72
|
-
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
79
|
requirements:
|
74
|
-
- -
|
80
|
+
- - ">="
|
75
81
|
- !ruby/object:Gem::Version
|
76
82
|
version: 1.3.5
|
77
|
-
none: false
|
78
83
|
description: biggs is a small ruby gem/rails plugin for formatting postal addresses
|
79
84
|
from over 60 countries.
|
80
85
|
email:
|
@@ -83,8 +88,8 @@ executables: []
|
|
83
88
|
extensions: []
|
84
89
|
extra_rdoc_files: []
|
85
90
|
files:
|
86
|
-
- .gitignore
|
87
|
-
- .rvmrc
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rvmrc"
|
88
93
|
- CHANGES.md
|
89
94
|
- Gemfile
|
90
95
|
- LICENSE
|
@@ -95,41 +100,40 @@ files:
|
|
95
100
|
- formats.yml
|
96
101
|
- init.rb
|
97
102
|
- lib/biggs.rb
|
98
|
-
- lib/biggs/
|
103
|
+
- lib/biggs/concern.rb
|
104
|
+
- lib/biggs/extractor.rb
|
99
105
|
- lib/biggs/format.rb
|
100
106
|
- lib/biggs/formatter.rb
|
101
107
|
- lib/biggs/version.rb
|
102
108
|
- spec/spec_helper.rb
|
103
|
-
- spec/unit/activerecord_spec.rb
|
104
109
|
- spec/unit/biggs_spec.rb
|
110
|
+
- spec/unit/concern_spec.rb
|
105
111
|
- spec/unit/format_spec.rb
|
106
112
|
homepage: https://github.com/yolk/biggs
|
107
113
|
licenses: []
|
108
|
-
|
114
|
+
metadata: {}
|
115
|
+
post_install_message:
|
109
116
|
rdoc_options: []
|
110
117
|
require_paths:
|
111
118
|
- lib
|
112
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
120
|
requirements:
|
114
|
-
- -
|
121
|
+
- - ">="
|
115
122
|
- !ruby/object:Gem::Version
|
116
123
|
version: '0'
|
117
|
-
none: false
|
118
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
125
|
requirements:
|
120
|
-
- -
|
126
|
+
- - ">="
|
121
127
|
- !ruby/object:Gem::Version
|
122
128
|
version: '0'
|
123
|
-
none: false
|
124
129
|
requirements: []
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
specification_version: 3
|
130
|
+
rubygems_version: 3.1.6
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
129
133
|
summary: biggs is a small ruby gem/rails plugin for formatting postal addresses from
|
130
134
|
over 60 countries.
|
131
135
|
test_files:
|
132
136
|
- spec/spec_helper.rb
|
133
|
-
- spec/unit/activerecord_spec.rb
|
134
137
|
- spec/unit/biggs_spec.rb
|
138
|
+
- spec/unit/concern_spec.rb
|
135
139
|
- spec/unit/format_spec.rb
|
data/lib/biggs/activerecord.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute'
|
2
|
-
|
3
|
-
module Biggs
|
4
|
-
module ActiveRecordAdapter
|
5
|
-
|
6
|
-
def self.included(base)
|
7
|
-
base.extend(InitialClassMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
module InitialClassMethods
|
11
|
-
def biggs(method_name=nil, options={})
|
12
|
-
self.class_attribute :biggs_value_methods
|
13
|
-
self.class_attribute :biggs_instance
|
14
|
-
|
15
|
-
self.send(:include, Biggs::ActiveRecordAdapter::InstanceMethods)
|
16
|
-
alias_method(method_name || :postal_address, :biggs_postal_address)
|
17
|
-
|
18
|
-
value_methods = {}
|
19
|
-
Biggs::Formatter::FIELDS.each do |field|
|
20
|
-
value_methods[field] = options.delete(field) if options[field]
|
21
|
-
end
|
22
|
-
|
23
|
-
self.biggs_value_methods = value_methods
|
24
|
-
self.biggs_instance = Biggs::Formatter.new(options)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
module InstanceMethods
|
29
|
-
|
30
|
-
def biggs_postal_address
|
31
|
-
self.class.biggs_instance.format(biggs_country, biggs_values)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def biggs_country
|
37
|
-
biggs_get_value(:country)
|
38
|
-
end
|
39
|
-
|
40
|
-
def biggs_values
|
41
|
-
values = {}
|
42
|
-
(Biggs::Formatter::FIELDS - [:country]).each do |field|
|
43
|
-
values[field] = biggs_get_value(field)
|
44
|
-
end
|
45
|
-
values
|
46
|
-
end
|
47
|
-
|
48
|
-
def biggs_get_value(field)
|
49
|
-
key = self.class.biggs_value_methods[field.to_sym] || field.to_sym
|
50
|
-
|
51
|
-
case key
|
52
|
-
when Symbol
|
53
|
-
self.send(key.to_sym)
|
54
|
-
when Proc
|
55
|
-
key.call(self).to_s
|
56
|
-
when Array
|
57
|
-
if key.all?{|it| it.is_a?(Symbol) }
|
58
|
-
key.map{|method| self.send(method) }.reject(&:blank?).join("\n")
|
59
|
-
else
|
60
|
-
raise "Biggs: Can't handle #{field} type Array with non-symbolic entries"
|
61
|
-
end
|
62
|
-
else
|
63
|
-
raise "Biggs: Can't handle #{field} type #{key.class}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|