Class: Geocoder::Result::SmartyStreets

Inherits:
Base
  • Object
show all
Defined in:
lib/geocoder/results/smarty_streets.rb

Instance Attribute Summary

Attributes inherited from Base

#cache_hit, #data

Instance Method Summary collapse

Methods inherited from Base

#initialize, #latitude, #longitude, #province, #province_code

Constructor Details

This class inherits a constructor from Geocoder::Result::Base

Instance Method Details

#addressObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/geocoder/results/smarty_streets.rb', line 17

def address
  parts =
    if international_endpoint?
      (1..12).map { |i| @data["address#{i}"] }
    else
      [
        delivery_line_1,
        delivery_line_2,
        last_line
      ]
    end
  parts.select{ |i| i.to_s != "" }.join(" ")
end

#cityObject



71
72
73
74
75
76
77
78
79
# File 'lib/geocoder/results/smarty_streets.rb', line 71

def city
  if international_endpoint?
    components['locality']
  elsif zipcode_endpoint?
    city_states.first['city']
  else
    components['city_name']
  end
end

#coordinatesObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/geocoder/results/smarty_streets.rb', line 5

def coordinates
  result = %w(latitude longitude).map do |i|
    zipcode_endpoint? ? zipcodes.first[i] : [i]
  end

  if result.compact.empty?
    nil
  else
    result
  end
end

#countryObject



51
52
53
54
55
# File 'lib/geocoder/results/smarty_streets.rb', line 51

def country
  international_endpoint? ?
    components['country_iso_3'] :
    "United States"
end

#country_codeObject



57
58
59
60
61
# File 'lib/geocoder/results/smarty_streets.rb', line 57

def country_code
  international_endpoint? ?
    components['country_iso_3'] :
    "US"
end

#fipsObject



97
98
99
100
101
# File 'lib/geocoder/results/smarty_streets.rb', line 97

def fips
  zipcode_endpoint? ?
    zipcodes.first['county_fips'] :
    ['county_fips']
end

#international_endpoint?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/geocoder/results/smarty_streets.rb', line 107

def international_endpoint?
  !@data['address1'].nil?
end

#stateObject



31
32
33
34
35
36
37
38
39
# File 'lib/geocoder/results/smarty_streets.rb', line 31

def state
  if international_endpoint?
    components['administrative_area']
  elsif zipcode_endpoint?
    city_states.first['state']
  else
    components['state_abbreviation']
  end
end

#state_codeObject



41
42
43
44
45
46
47
48
49
# File 'lib/geocoder/results/smarty_streets.rb', line 41

def state_code
  if international_endpoint?
    components['administrative_area']
  elsif zipcode_endpoint?
    city_states.first['state_abbreviation']
  else
    components['state_abbreviation']
  end
end

#streetObject

Extra methods not in base.rb ————————



65
66
67
68
69
# File 'lib/geocoder/results/smarty_streets.rb', line 65

def street
  international_endpoint? ?
    components['thoroughfare_name'] :
    components['street_name']
end

#zip4Object Also known as: postal_code_extended



92
93
94
# File 'lib/geocoder/results/smarty_streets.rb', line 92

def zip4
  components['plus4_code']
end

#zipcodeObject Also known as: postal_code



81
82
83
84
85
86
87
88
89
# File 'lib/geocoder/results/smarty_streets.rb', line 81

def zipcode
  if international_endpoint?
    components['postal_code']
  elsif zipcode_endpoint?
    zipcodes.first['zipcode']
  else
    components['zipcode']
  end
end

#zipcode_endpoint?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/geocoder/results/smarty_streets.rb', line 103

def zipcode_endpoint?
  zipcodes.any?
end