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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd9ebb5dbcc6d69377b28f76b56b98d746ecf9a3
4
- data.tar.gz: c698853f917f3755ed5afbf6b5fbee155f5b7b09
3
+ metadata.gz: 6284773a18364d9fe9d92dd813773600962ae91d
4
+ data.tar.gz: 5d07abcc7f4041971831df9d44d3365670b6fd50
5
5
  SHA512:
6
- metadata.gz: f466cda1ce5cd6ddb84c58497a308988e8b81e903d419c97992b541891172266ea086f5fc398bf6459f0c1ac96d7e781b3fcfdd2fc4a5516663e4232f2e7447d
7
- data.tar.gz: 595ee7159deff55287172552e8eedf055f14e2a17ec0c6ef694f8e553f45624026d6f4ba682fe112c39e7c6c1d46b97ac468630a86db3f6419aef6fb58656b91
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 to_h
31
- attributes
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(attributes).render
35
+ AddressFormatter::Text.new(to_h).render
36
36
  end
37
37
 
38
38
  def to_html(params={})
39
- AddressFormatter::HTML.new(attributes).render(params)
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 |(key, value), hash|
22
- hash[key] = value && content_tag(:span, value, itemprop: ItemProp[key])
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='', attributes={})
27
- attrs = attributes.map {|k,v| k.to_s + (v ? "=\"#{v}\"" : '') }.unshift('').join(' ')
28
- "<#{tag}#{attrs}>#{content}</#{tag}>"
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
@@ -1,3 +1,3 @@
1
1
  module Postal
2
- VERSION = "0.1.5"
2
+ VERSION = "0.9.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postal_address
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Melchert