postal_address 0.9.4 → 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/postal_address/address.rb +4 -4
- data/lib/postal_address/formatters/html.rb +1 -1
- data/lib/postal_address/version.rb +1 -1
- data/spec/postal_address_spec.rb +30 -27
- data/spec/spec_helper.rb +1 -4
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 732395d6e01e69eb058f8040e1e4897b00d5362126261ce8d5519308cf6f83bf
|
4
|
+
data.tar.gz: abf24032951733529ab117b7b985655183a5fb2d127e84c4f4d9cd405b02afb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25f0707107ac25f08e63cda2a703b81e06230113eb3e5fb197f4dc6396c24c21efc0fc204aa6a6faf4f5837c865d11efeca059e2c3c77d3daa69835c49774ac7
|
7
|
+
data.tar.gz: 7727b70db57733a9edc17410324278c6457314831b85c445a5cf0377ac89b1d71c51f29dc22c6a759267415ccca4cbfff2a0ec5fc944d5467af74b0845bc122e
|
@@ -25,12 +25,12 @@ module Postal
|
|
25
25
|
Fields.zip(values).to_h
|
26
26
|
end
|
27
27
|
|
28
|
-
def to_s(**
|
29
|
-
AddressFormatter::Text.new(to_h).render(
|
28
|
+
def to_s(**)
|
29
|
+
AddressFormatter::Text.new(to_h).render(**)
|
30
30
|
end
|
31
31
|
|
32
|
-
def to_html(**
|
33
|
-
AddressFormatter::HTML.new(to_h).render(
|
32
|
+
def to_html(**)
|
33
|
+
AddressFormatter::HTML.new(to_h).render(**)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -14,7 +14,7 @@ module Postal
|
|
14
14
|
def render(**params)
|
15
15
|
tagname = params.delete(:tag) || :p
|
16
16
|
content = super.gsub("\n", "<br>")
|
17
|
-
tag tagname, content, params.merge(itemscope: nil, itemtype: ItemType)
|
17
|
+
tag tagname, content, **params.merge(itemscope: nil, itemtype: ItemType)
|
18
18
|
end
|
19
19
|
|
20
20
|
private
|
data/spec/postal_address_spec.rb
CHANGED
@@ -1,29 +1,25 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require '
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'minitest/autorun'
|
5
|
-
require 'minitest/spec'
|
6
|
-
require 'postal_address'
|
2
|
+
require 'spec_helper'
|
7
3
|
|
8
4
|
describe Postal do
|
9
5
|
it "should load the formats" do
|
10
|
-
Postal.address_formats.wont_be :empty?
|
11
|
-
Postal.address_formats.must_be_kind_of Hash
|
6
|
+
_(Postal.address_formats).wont_be :empty?
|
7
|
+
_(Postal.address_formats).must_be_kind_of Hash
|
12
8
|
end
|
13
9
|
|
14
10
|
it "should load the country_name" do
|
15
|
-
Postal.country_names.wont_be :empty?
|
16
|
-
Postal.country_names.must_be_kind_of Hash
|
11
|
+
_(Postal.country_names).wont_be :empty?
|
12
|
+
_(Postal.country_names).must_be_kind_of Hash
|
17
13
|
end
|
18
14
|
|
19
15
|
it "should read/write home country" do
|
20
|
-
Postal.home_country =
|
21
|
-
Postal.home_country.must_equal 'de'
|
16
|
+
Postal.home_country = :de
|
17
|
+
_(Postal.home_country).must_equal 'de'
|
22
18
|
end
|
23
19
|
|
24
|
-
it "should
|
25
|
-
Postal.home_country =
|
26
|
-
Postal.home_country.must_equal 'de'
|
20
|
+
it "should sanititze home country" do
|
21
|
+
Postal.home_country = 'DE'
|
22
|
+
_(Postal.home_country).must_equal 'de'
|
27
23
|
end
|
28
24
|
|
29
25
|
describe "Instance" do
|
@@ -32,65 +28,72 @@ describe Postal do
|
|
32
28
|
}
|
33
29
|
|
34
30
|
let(:address) do
|
35
|
-
Postal::Address.new(
|
31
|
+
Postal::Address.new(
|
36
32
|
recipient: 'Tobias Füncke',
|
37
33
|
street: '101 Broadway',
|
38
34
|
city: 'New York City',
|
39
35
|
zip: '10002',
|
40
36
|
state: 'NY',
|
41
37
|
country_code: 'us'
|
42
|
-
|
38
|
+
)
|
43
39
|
end
|
44
40
|
|
45
41
|
it "should respond to to_h" do
|
46
42
|
r = address.to_h
|
47
|
-
r.must_be_kind_of Hash
|
48
|
-
r.keys.length.must_equal 7
|
43
|
+
_(r).must_be_kind_of Hash
|
44
|
+
_(r.keys.length).must_equal 7
|
49
45
|
end
|
50
46
|
|
51
47
|
it "should format to US format" do
|
52
|
-
address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002\nUnited States of America"
|
48
|
+
_(address.to_s).must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002\nUnited States of America"
|
53
49
|
end
|
54
50
|
|
55
51
|
it "should format to FR format" do
|
56
52
|
address.country_code = 'fr'
|
57
53
|
address.city = 'Paris'
|
58
|
-
address.to_s.must_equal "Tobias Füncke\n101 Broadway\n10002 Paris\nFrance"
|
54
|
+
_(address.to_s).must_equal "Tobias Füncke\n101 Broadway\n10002 Paris\nFrance"
|
59
55
|
end
|
60
56
|
|
61
57
|
it "should format to DE format" do
|
62
58
|
address.country_code = 'de'
|
63
59
|
address.city = 'Berlin'
|
64
|
-
address.to_s.must_equal "Tobias Füncke\n101 Broadway\n10002 Berlin\nGermany"
|
60
|
+
_(address.to_s).must_equal "Tobias Füncke\n101 Broadway\n10002 Berlin\nGermany"
|
65
61
|
end
|
66
62
|
|
67
63
|
it "should not print the country if in home country" do
|
68
64
|
Postal.home_country = 'us'
|
69
|
-
address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002"
|
65
|
+
_(address.to_s).must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002"
|
70
66
|
end
|
71
67
|
|
72
68
|
it "should print the country if not in home country" do
|
73
69
|
Postal.home_country = 'de'
|
74
|
-
address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002\nUnited States of America"
|
70
|
+
_(address.to_s).must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002\nUnited States of America"
|
75
71
|
end
|
76
72
|
|
77
73
|
it "should use default formatting with state if format for country code is not available" do
|
78
74
|
address.country_code = nil
|
79
|
-
address.to_s.must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002"
|
75
|
+
_(address.to_s).must_equal "Tobias Füncke\n101 Broadway\nNew York City NY 10002"
|
80
76
|
end
|
81
77
|
|
82
78
|
it "should use default formatting without state if format for country code is not available" do
|
83
79
|
address.country_code = nil
|
84
80
|
address.state = nil
|
85
|
-
address.to_s.must_equal "Tobias Füncke\n101 Broadway\n10002 New York City"
|
81
|
+
_(address.to_s).must_equal "Tobias Füncke\n101 Broadway\n10002 New York City"
|
86
82
|
end
|
87
83
|
|
88
84
|
it "should return html" do
|
89
|
-
address.to_html.must_equal "<p itemscope itemtype=\"http://schema.org/PostalAddress\"><span itemprop=\"name\">Tobias Füncke</span><br><span itemprop=\"streetAddress\">101 Broadway</span><br><span itemprop=\"addressLocality\">New York City</span> <span itemprop=\"addressRegion\">NY</span> <span itemprop=\"postalCode\">10002</span><br><span itemprop=\"addressCountry\">United States of America</span></p>"
|
85
|
+
_(address.to_html).must_equal "<p itemscope itemtype=\"http://schema.org/PostalAddress\"><span itemprop=\"name\">Tobias Füncke</span><br><span itemprop=\"streetAddress\">101 Broadway</span><br><span itemprop=\"addressLocality\">New York City</span> <span itemprop=\"addressRegion\">NY</span> <span itemprop=\"postalCode\">10002</span><br><span itemprop=\"addressCountry\">United States of America</span></p>"
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return html with default formatting" do
|
89
|
+
address.country_code = nil
|
90
|
+
address.state = nil
|
91
|
+
_(address.to_html).must_equal "<p itemscope itemtype=\"http://schema.org/PostalAddress\"><span itemprop=\"name\">Tobias Füncke</span><br><span itemprop=\"streetAddress\">101 Broadway</span><br><span itemprop=\"postalCode\">10002</span> <span itemprop=\"addressLocality\">New York City</span></p>"
|
90
92
|
end
|
91
93
|
|
92
94
|
it "should return custom html" do
|
93
|
-
address.to_html(tag: :section, itemprop: 'address').must_equal "<section itemprop=\"address\" itemscope itemtype=\"http://schema.org/PostalAddress\"><span itemprop=\"name\">Tobias Füncke</span><br><span itemprop=\"streetAddress\">101 Broadway</span><br><span itemprop=\"addressLocality\">New York City</span> <span itemprop=\"addressRegion\">NY</span> <span itemprop=\"postalCode\">10002</span><br><span itemprop=\"addressCountry\">United States of America</span></section>"
|
95
|
+
_(address.to_html(tag: :section, itemprop: 'address')).must_equal "<section itemprop=\"address\" itemscope itemtype=\"http://schema.org/PostalAddress\"><span itemprop=\"name\">Tobias Füncke</span><br><span itemprop=\"streetAddress\">101 Broadway</span><br><span itemprop=\"addressLocality\">New York City</span> <span itemprop=\"addressRegion\">NY</span> <span itemprop=\"postalCode\">10002</span><br><span itemprop=\"addressCountry\">United States of America</span></section>"
|
94
96
|
end
|
97
|
+
|
95
98
|
end
|
96
99
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postal_address
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Melchert
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bundler
|
@@ -79,7 +78,6 @@ homepage: https://github.com/max-power/postal_address
|
|
79
78
|
licenses:
|
80
79
|
- MIT
|
81
80
|
metadata: {}
|
82
|
-
post_install_message:
|
83
81
|
rdoc_options: []
|
84
82
|
require_paths:
|
85
83
|
- lib
|
@@ -94,8 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
92
|
- !ruby/object:Gem::Version
|
95
93
|
version: '0'
|
96
94
|
requirements: []
|
97
|
-
rubygems_version: 3.
|
98
|
-
signing_key:
|
95
|
+
rubygems_version: 3.6.2
|
99
96
|
specification_version: 4
|
100
97
|
summary: International postal address formatting with HTML Microformats
|
101
98
|
test_files:
|