class AddressSimilarityParameters

This class encapsulates parameters that are needed for address-similarity in Rosette API.

Attributes

address1[RW]

Address to be compared to address2

address2[RW]

Address to be compared to address1

Public Instance Methods

load_params() click to toggle source

Converts this class to Hash with its keys in lower CamelCase.

Returns the new Hash.

# File address_similarity_parameters.rb, line 32
def load_params
  validate_params
  to_hash
    .compact
    .transform_keys { |key| key.to_s.split('_').map(&:capitalize).join.sub!(/\D/, &:downcase) }
end
to_hash() click to toggle source

Converts this class to Hash.

Returns the new Hash.

# File address_similarity_parameters.rb, line 42
def to_hash
  {
    address1: @address1.is_a?(AddressParameter) ? @address1.load_param : @address1,
    address2: @address2.is_a?(AddressParameter) ? @address2.load_param : @address2
  }
end
validate_params() click to toggle source

Validates the parameters by checking if address1 and address2 are instances of AddressParameters or Strings.

# File address_similarity_parameters.rb, line 21
def validate_params
  a1_msg = 'address1 option can only be an instance of an AddressParameter or a String'
  raise BadRequestError.new(a1_msg) if [String, AddressParameter].none? { |clazz| @address1.is_a? clazz }

  a2_msg = 'address2 option can only be an instance of an AddressParameter or a String'
  raise BadRequestError.new(a2_msg) if [String, AddressParameter].none? { |clazz| @address2.is_a? clazz }
end

Protected Instance Methods

initialize(address1, address2) click to toggle source
# File address_similarity_parameters.rb, line 14
def initialize(address1, address2) # :notnew:
  @address1 = address1
  @address2 = address2
end