class MatchMate::Address

Public Class Methods

languages() click to toggle source
# File lib/match-mate/address.rb, line 3
def self.languages
  @languages ||= MatchMate.config.languages || DEFAULTS[:languages]
end
new(input_object_or_string) click to toggle source
# File lib/match-mate/address.rb, line 7
def initialize(input_object_or_string)
  # Accepts any address object that responds to a to_s method
  @input_string = input_object_or_string.to_s
end

Public Instance Methods

==(other_address) click to toggle source
# File lib/match-mate/address.rb, line 37
def ==(other_address)
  AddressMatcher.new(self, other_address).match?
end
Also aliased as: eql?, ===
===(other_address)
Alias for: ==
city() click to toggle source
# File lib/match-mate/address.rb, line 25
def city
  components[:city]
end
city_and_state() click to toggle source

Normalized Compositites

# File lib/match-mate/address.rb, line 46
def city_and_state
  [city, state].compact.join(', ')
end
eql?(other_address)
Alias for: ==
house_number() click to toggle source
# File lib/match-mate/address.rb, line 33
def house_number
  components[:house_number]
end
postcode() click to toggle source
# File lib/match-mate/address.rb, line 21
def postcode
  limit_to components[:postcode], MatchMate.config.postcode_limit
end
road() click to toggle source

Basic Components for comparsion

# File lib/match-mate/address.rb, line 13
def road
  expand components[:road]
end
state() click to toggle source
# File lib/match-mate/address.rb, line 29
def state
  components[:state]
end
street_address() click to toggle source
# File lib/match-mate/address.rb, line 50
def street_address
  [house_number, road.last].compact.join(' ')
end
street_adress_with_unit() click to toggle source
# File lib/match-mate/address.rb, line 54
def street_adress_with_unit
  [street_address, unit].compact.join(' ')
end
to_s() click to toggle source
# File lib/match-mate/address.rb, line 58
def to_s
  [street_adress_with_unit, city_and_state, zip_code].compact.join(', ')
end
unit() click to toggle source
# File lib/match-mate/address.rb, line 17
def unit
  extract_integers components[:unit]
end

Private Instance Methods

components() click to toggle source
# File lib/match-mate/address.rb, line 71
def components
  {}.tap do |components|
    parsed_object.each do |component|
      components[component[:label]] = component[:value]
    end
  end
end
expand(string) click to toggle source
# File lib/match-mate/address.rb, line 89
def expand(string)
  return if string.blank?

  Postal::Expand.expand_address string, languages: self.class.languages
end
extract_integers(string, limit = nil) click to toggle source
# File lib/match-mate/address.rb, line 64
def extract_integers(string, limit = nil)
  return if string.blank?

  value = string.gsub(/\D/, '')
  limit ? value.first(limit) : value
end
limit_to(string, limit) click to toggle source
# File lib/match-mate/address.rb, line 83
def limit_to(string, limit)
  return string if string.blank? || limit.blank?

  string.first(limit)
end
parsed_object() click to toggle source
# File lib/match-mate/address.rb, line 79
def parsed_object
  @parsed_object ||= Postal::Parser.parse_address @input_string, languages: self.class.languages
end