postal_address 0.1.5 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postal_address/address.rb +12 -20
- data/lib/postal_address/formatters/html.rb +8 -5
- data/lib/postal_address/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6284773a18364d9fe9d92dd813773600962ae91d
|
4
|
+
data.tar.gz: 5d07abcc7f4041971831df9d44d3365670b6fd50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b3807375fb3e684a72ee605f0836b7f0927faaa04a86918615d619b253059a3d4c81ecdc1246ff4f394d6ec59821de2705a336bf01f278c9956059f37afd0b9
|
7
|
+
data.tar.gz: e2d9a0d08082ef7f994095360ef0c503a0bf2cf636a1e72bd0b9ae587ba21f9a6aa279fc5a4b0492622f08ffab0626a61c8c6a45a03272caa818c2571f8c7037
|
@@ -12,13 +12,7 @@ module Postal
|
|
12
12
|
alias_method :province=, :state=
|
13
13
|
alias_method :territory=, :state=
|
14
14
|
alias_method :administrative_area_level_1=, :state=
|
15
|
-
|
16
|
-
def initialize(attrs={})
|
17
|
-
attrs.each do |attr, value|
|
18
|
-
self.public_send(:"#{attr}=", value) if self.respond_to?(:"#{attr}=")
|
19
|
-
end if attrs
|
20
|
-
end
|
21
|
-
|
15
|
+
|
22
16
|
def country_code=(code)
|
23
17
|
@country_code = Postal.sanitize(code)
|
24
18
|
end
|
@@ -26,25 +20,23 @@ module Postal
|
|
26
20
|
def country
|
27
21
|
@country ||= Postal.country_names[country_code]
|
28
22
|
end
|
29
|
-
|
30
|
-
def
|
31
|
-
|
23
|
+
|
24
|
+
def initialize(attrs={})
|
25
|
+
attrs.each do |field, value|
|
26
|
+
self.public_send(:"#{field}=", value) if self.respond_to?(:"#{field}=")
|
27
|
+
end if attrs
|
32
28
|
end
|
33
29
|
|
30
|
+
def to_h
|
31
|
+
Fields.each_with_object({}) { |field, hash| hash[field] = public_send(field) }
|
32
|
+
end
|
33
|
+
|
34
34
|
def to_s
|
35
|
-
AddressFormatter::Text.new(
|
35
|
+
AddressFormatter::Text.new(to_h).render
|
36
36
|
end
|
37
37
|
|
38
38
|
def to_html(params={})
|
39
|
-
AddressFormatter::HTML.new(
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def attributes
|
45
|
-
Fields.each_with_object({}) do |key, hash|
|
46
|
-
hash[key] = public_send(key)
|
47
|
-
end
|
39
|
+
AddressFormatter::HTML.new(to_h).render(params)
|
48
40
|
end
|
49
41
|
end
|
50
42
|
end
|
@@ -18,14 +18,17 @@ module Postal
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def address_data
|
21
|
-
super.each_with_object({}) do |(
|
22
|
-
hash[
|
21
|
+
super.each_with_object({}) do |(field, value), hash|
|
22
|
+
hash[field] = value && content_tag(:span, value, itemprop: ItemProp[field])
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def content_tag(tag, content='',
|
27
|
-
|
28
|
-
|
26
|
+
def content_tag(tag, content='', attrs={})
|
27
|
+
"<#{tag}#{tag_attributes(attrs)}>#{content}</#{tag}>"
|
28
|
+
end
|
29
|
+
|
30
|
+
def tag_attributes(attrs)
|
31
|
+
attrs.map { |k,v| v ? %[#{k}="#{v}"] : k }.unshift('').join(' ')
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|