dc_address_parser 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dc_address_parser/address.rb +12 -13
- data/lib/dc_address_parser/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: d0f02097fc791616bc01aa7ffb7f805ea0f3114d
|
4
|
+
data.tar.gz: 1c6dc663264c0ce46aa429878aaa3904f588399a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb3b1c639d91198059c2daf4910d9e87dfc6b09b0cd941b78e2e05ebd16821fb8731d8df3443f959963f04ae0da868bf7abf7ae0c188c4a66e7c1e6bc0d0daf
|
7
|
+
data.tar.gz: 6273130d36944c420b2af2995db6bdcc2f2ee5d8521203077f067fa4cc3375db687b2539f174416a89792fee324152d698ed82664b02646c34c0eef63d868319
|
@@ -11,10 +11,15 @@ module DcAddressParser
|
|
11
11
|
STREET_TYPE_ABV_REGEX = /\b(#{Regexp.union(DcAddressParser::STREET_TYPES.values)})\b/
|
12
12
|
QUADRANT_REGEX = /([NS][EW])/
|
13
13
|
|
14
|
+
PARTS = [:number, :number_suffix, :street_name, :street_type, :quadrant, :unit_number]
|
14
15
|
REQUIRED_PARTS = [:number, :street_name, :street_type, :quadrant]
|
15
16
|
|
16
|
-
def initialize(
|
17
|
-
|
17
|
+
def initialize(address_or_hash)
|
18
|
+
if address_or_hash.class == Hash
|
19
|
+
address_or_hash = PARTS.clone.map { |part| address_or_hash[part] }.join(" ")
|
20
|
+
end
|
21
|
+
@raw_address = @address = address_or_hash
|
22
|
+
|
18
23
|
normalize!
|
19
24
|
REQUIRED_PARTS.each do |part|
|
20
25
|
raise InvalidAddress, "#{part.to_s.sub("_", " ")} is missing" if send(part).nil?
|
@@ -34,7 +39,7 @@ module DcAddressParser
|
|
34
39
|
@street_name ||= begin
|
35
40
|
street_name = match(
|
36
41
|
/#{number}(-?#{unit_number}|\s#{Regexp.escape number_suffix.to_s})?
|
37
|
-
\s#{STREET_NAME_REGEX}\s
|
42
|
+
\s#{STREET_NAME_REGEX}\s(?=#{STREET_TYPE_REGEX})/x, 2)
|
38
43
|
|
39
44
|
if street_name =~ /\A[0-9]+\z/
|
40
45
|
street_name = ActiveSupport::Inflector.ordinalize(street_name).upcase
|
@@ -46,7 +51,7 @@ module DcAddressParser
|
|
46
51
|
alias_method :street, :street_name
|
47
52
|
|
48
53
|
def street_type
|
49
|
-
@street_type ||= match
|
54
|
+
@street_type ||= match(STREET_TYPE_REGEX) || "STREET"
|
50
55
|
end
|
51
56
|
|
52
57
|
def quadrant
|
@@ -69,15 +74,9 @@ module DcAddressParser
|
|
69
74
|
alias_method :unit, :unit_number
|
70
75
|
|
71
76
|
def to_h
|
72
|
-
{
|
73
|
-
|
74
|
-
|
75
|
-
street_name: street_name,
|
76
|
-
street_type: street_type,
|
77
|
-
quadrant: quadrant,
|
78
|
-
unit_number: unit_number,
|
79
|
-
city: DcAddressParser::CITY
|
80
|
-
}
|
77
|
+
hash = {}
|
78
|
+
PARTS.each { |part| hash[part] = send(part) }
|
79
|
+
hash.merge({city: DcAddressParser::CITY})
|
81
80
|
end
|
82
81
|
|
83
82
|
def to_s(include_city=false)
|