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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07f0c5a7d4ac58c6defcc2e5e4f9053fe486137c
4
- data.tar.gz: 7421f846de941ad02a85fb5f1c42990b41da3484
3
+ metadata.gz: d0f02097fc791616bc01aa7ffb7f805ea0f3114d
4
+ data.tar.gz: 1c6dc663264c0ce46aa429878aaa3904f588399a
5
5
  SHA512:
6
- metadata.gz: 918a182fa39f6bf528f582531745a9871fc48587fcedb331e7b674d837a27e2a6b36a6dc20a6d4cc5d91d4b6daff927df99dbd93e50c7e69c8f4724cb113d0d5
7
- data.tar.gz: 5b2fcd0689f395b98a0c1fb42d4859f97d89425ae47586334ee1ac7abe1c0e42a46175042742b30a19a490b1e6f44b2ca2c98bd2c98cb96bd789a91c2f1128b4
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(raw_address)
17
- @raw_address = @address = raw_address
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#{STREET_TYPE_REGEX}/x, 2)
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 STREET_TYPE_REGEX
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
- number: number,
74
- number_suffix: number_suffix,
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)
@@ -1,3 +1,3 @@
1
1
  module DcAddressParser
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dc_address_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter