StreetAddress 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.rdoc +3 -2
  2. data/lib/street_address.rb +39 -29
  3. metadata +4 -4
@@ -26,9 +26,10 @@ Parse United States addresses.
26
26
  address.state_name # District of columbia
27
27
  address.street_type # Ave
28
28
  address.intersection? # false
29
-
29
+ address.to_s # "1600 Pennsylvania Ave, Washington, DC 20500"
30
+ address.to_s(:line1) # 1600 Pennsylvania Ave
30
31
  StreetAddress::US.parse("1600 Pennsylvania Ave") # nil not a full address
31
32
 
32
33
  === Gemfile:
33
34
  To use from your Gemfile:
34
- gem 'StreetAddress', '1.0.2', :require => "street_address
35
+ gem 'StreetAddress', '1.0.2', :require => "street_address"
@@ -64,7 +64,7 @@
64
64
 
65
65
  module StreetAddress
66
66
  class US
67
- VERSION = '1.0.2'
67
+ VERSION = '1.0.3'
68
68
  DIRECTIONAL = {
69
69
  "north" => "N",
70
70
  "northeast" => "NE",
@@ -809,37 +809,47 @@ module StreetAddress
809
809
  !street2.nil?
810
810
  end
811
811
 
812
- def to_s
812
+ def line1(s = "")
813
+ s += number
814
+ s += " " + prefix unless prefix.nil?
815
+ s += " " + street unless street.nil?
816
+ s += " " + street_type unless street_type.nil?
817
+ if( !unit_prefix.nil? && !unit.nil? )
818
+ s += " " + unit_prefix
819
+ s += " " + unit
820
+ elsif( unit_prefix.nil? && !unit.nil? )
821
+ s += " #" + unit
822
+ end
823
+ s += " " + suffix unless suffix.nil?
824
+ return s
825
+ end
826
+
827
+ def to_s(format = :default)
813
828
  s = ""
814
- if intersection?
815
- s += prefix + " " unless prefix.nil?
816
- s += street
817
- s += " " + street_type unless street_type.nil?
818
- s += " " + suffix unless suffix.nil?
819
- s += " and"
820
- s += " " + prefix2 unless prefix2.nil?
821
- s += " " + street2
822
- s += " " + street_type2 unless street_type2.nil?
823
- s += " " + suffix2 unless suffix2.nil?
824
- s += ", " + city unless city.nil?
825
- s += ", " + state unless state.nil?
826
- s += " " + postal_code unless postal_code.nil?
829
+ case format
830
+ when :line1
831
+ s += line1(s)
827
832
  else
828
- s += number
829
- s += " " + prefix unless prefix.nil?
830
- s += " " + street unless street.nil?
831
- s += " " + street_type unless street_type.nil?
832
- if( !unit_prefix.nil? && !unit.nil? )
833
- s += " " + unit_prefix
834
- s += " " + unit
835
- elsif( unit_prefix.nil? && !unit.nil? )
836
- s += " #" + unit
833
+ if intersection?
834
+ s += prefix + " " unless prefix.nil?
835
+ s += street
836
+ s += " " + street_type unless street_type.nil?
837
+ s += " " + suffix unless suffix.nil?
838
+ s += " and"
839
+ s += " " + prefix2 unless prefix2.nil?
840
+ s += " " + street2
841
+ s += " " + street_type2 unless street_type2.nil?
842
+ s += " " + suffix2 unless suffix2.nil?
843
+ s += ", " + city unless city.nil?
844
+ s += ", " + state unless state.nil?
845
+ s += " " + postal_code unless postal_code.nil?
846
+ else
847
+ s += line1(s)
848
+ s += ", " + city unless city.nil?
849
+ s += ", " + state unless state.nil?
850
+ s += " " + postal_code unless postal_code.nil?
851
+ s += "-" + postal_code_ext unless postal_code_ext.nil?
837
852
  end
838
- s += " " + suffix unless suffix.nil?
839
- s += ", " + city unless city.nil?
840
- s += ", " + state unless state.nil?
841
- s += " " + postal_code unless postal_code.nil?
842
- s += "-" + postal_code_ext unless postal_code_ext.nil?
843
853
  end
844
854
  return s
845
855
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: StreetAddress
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 2
10
- version: 1.0.2
9
+ - 3
10
+ version: 1.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Derrek Long
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-07 00:00:00 -07:00
19
+ date: 2011-09-21 00:00:00 -07:00
20
20
  default_executable:
21
21
  dependencies: []
22
22