Class: Pipl::Address
Instance Attribute Summary collapse
-
#apartment ⇒ String
Apartment.
-
#city ⇒ String
City.
-
#country ⇒ String
2 letters country code.
-
#display ⇒ String
Well formatted representation of this address for display purposes.
-
#house ⇒ String
House.
-
#po_box ⇒ String
Post Office box number.
-
#raw ⇒ String
Unparsed address.
-
#state ⇒ String
2 letters state code.
-
#street ⇒ String
Street.
-
#type ⇒ String
Type of association of this address to a person.
-
#zip_code ⇒ String
Zip Code.
Attributes inherited from Field
#current, #inferred, #last_seen, #valid_since
Instance Method Summary collapse
- #country_full ⇒ Object
-
#initialize(params = {}) ⇒ Address
constructor
A new instance of Address.
- #is_searchable? ⇒ Boolean
- #is_sole_searchable? ⇒ Boolean
- #is_valid_country? ⇒ Boolean
- #is_valid_state? ⇒ Boolean
- #state_full ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods inherited from Field
base_params_from_hash, extra_metadata, from_hash
Methods included from Utils
alnum_chars, alpha_chars, date_to_str, extract_rate_limits, is_valid_url?, str_to_date, titleize, to_utf8
Constructor Details
#initialize(params = {}) ⇒ Address
Returns a new instance of Address.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/pipl/fields.rb', line 133 def initialize(params={}) super params @country = params[:country] @state = params[:state] @city = params[:city] @street = params[:street] @house = params[:house] @apartment = params[:apartment] @zip_code = params[:zip_code] @po_box = params[:po_box] @type = params[:type] @raw = params[:raw] @display = params[:display] end |
Instance Attribute Details
#apartment ⇒ String
Returns Apartment.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#city ⇒ String
Returns City.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#country ⇒ String
Returns 2 letters country code.
131 132 133 |
# File 'lib/pipl/fields.rb', line 131 def country @country end |
#display ⇒ String
Returns well formatted representation of this address for display purposes.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#house ⇒ String
Returns House.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#po_box ⇒ String
Returns Post Office box number.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#raw ⇒ String
Returns Unparsed address.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#state ⇒ String
Returns 2 letters state code.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#street ⇒ String
Returns Street.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#type ⇒ String
Returns Type of association of this address to a person. One of ‘home`, `work` or `old`.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
#zip_code ⇒ String
Returns Zip Code.
131 |
# File 'lib/pipl/fields.rb', line 131 attr_accessor :country, :state, :city, :street, :house, :apartment, :zip_code, :po_box, :type, :raw, :display |
Instance Method Details
#country_full ⇒ Object
171 172 173 |
# File 'lib/pipl/fields.rb', line 171 def country_full Pipl::COUNTRIES[@country.upcase.to_sym] if @country end |
#is_searchable? ⇒ Boolean
163 164 165 |
# File 'lib/pipl/fields.rb', line 163 def is_searchable? [@raw, @country, @state, @city].any? {|x| ! x.to_s.empty?} end |
#is_sole_searchable? ⇒ Boolean
167 168 169 |
# File 'lib/pipl/fields.rb', line 167 def is_sole_searchable? ! @raw.to_s.empty? || [@city, @street, @house].all? {|x| ! x.to_s.empty?} end |
#is_valid_country? ⇒ Boolean
148 149 150 |
# File 'lib/pipl/fields.rb', line 148 def is_valid_country? @country && Pipl::COUNTRIES.key?(@country.upcase.to_sym) end |
#is_valid_state? ⇒ Boolean
152 153 154 155 |
# File 'lib/pipl/fields.rb', line 152 def is_valid_state? is_valid_country? && Pipl::STATES.key?(@country.upcase.to_sym) and @state && Pipl::STATES[@country.upcase.to_sym].key?(@state.upcase.to_sym) end |
#state_full ⇒ Object
175 176 177 |
# File 'lib/pipl/fields.rb', line 175 def state_full Pipl::STATES[@country.upcase.to_sym][@state.upcase.to_sym] if is_valid_state? end |
#to_hash ⇒ Object
157 158 159 160 161 |
# File 'lib/pipl/fields.rb', line 157 def to_hash {country: @country, state: @state, city: @city, street: @street, house: @house, apartment: @apartment, zip_code: @zip_code, po_box: @po_box, raw: @raw} .reject { |_, value| value.nil? } end |
#to_s ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/pipl/fields.rb', line 179 def to_s return @display if @display country = @state ? @country : country_full state = @city ? @state : state_full vals = [@street, @city, state, country] s = vals.any? ? vals.select { |v| v }.join(', ') : '' if @street && (@house || @apartment) prefix = [@house, @apartment].select { |v| v && ! v.empty? }.join('-') s = prefix + ' ' + (s || '') end if @po_box && @street.nil? s = "P.O. Box #{@po_box} " + (s || '') end s ? Pipl::Utils.to_utf8(s) : '' end |