<commit_before>module UPS
  class Address
    attr_accessor :address1, :city, :state, :zip, :country

    def initialize(address={})
      @address1 = address[:address1]
      @city = address[:city]
      @state = address[:state]
      @zip = address[:zip]
      @country = address[:country]
    end

    def valid?
      return false if response.has_key? 'NoCandidatesIndicator'
      return false if response.has_key? 'AmbiguousAddressIndicator'
      response.has_key?('ValidAddressIndicator')
    end

    def recommendations
      return [] if valid?
      response['AddressKeyFormat'].map do |recommendation|
        RecommendedAddress.new(recommendation)
      end
    end

    def response
      @response ||= API::AddressValidationRequest.new(self).response
    end
  end

  class RecommendedAddress < Address
    def initialize(recommendation)
      address1 = if recommendation['AddressLine'].kind_of? Array
        recommendation['AddressLine'][0]
      else
        recommendation['AddressLine']
      end

      city = recommendation['PoliticalDivision2']
      state = recommendation['PoliticalDivision1']
      zip = recommendation['PostcodePrimaryLow']
      country = recommendation['CountryCode']

      super(:address1 => address1,
            :city => city,
            :state => state,
            :zip => zip,
            :country => country)<commit_msg>Add address2 support<commit_after>module UPS
  class Address
    attr_accessor :address1, :address2, :city, :state, :zip, :country

    def initialize(address={})
      @address1 = address[:address1]
      @address2 = address[:address2]
      @city = address[:city]
      @state = address[:state]
      @zip = address[:zip]
      @country = address[:country]
    end

    def valid?
      return false if response.has_key? 'NoCandidatesIndicator'
      return false if response.has_key? 'AmbiguousAddressIndicator'
      response.has_key?('ValidAddressIndicator')
    end

    def recommendations
      return [] if valid?
      response['AddressKeyFormat'].map do |recommendation|
        RecommendedAddress.new(recommendation)
      end
    end

    def response
      @response ||= API::AddressValidationRequest.new(self).response
    end
  end

  class RecommendedAddress < Address
    def initialize(recommendation)
      address1 = if recommendation['AddressLine'].kind_of? Array
        recommendation['AddressLine'][0]
      else
        recommendation['AddressLine']
      end

      address2 = if recommendation['AddressLine'].kind_of? Array
        recommendation['AddressLine'][1]
      else
        nil
      end

      city = recommendation['PoliticalDivision2']
      state = recommendation['PoliticalDivision1']
      zip = recommendation['PostcodePrimaryLow']
      country = recommendation['CountryCode']

      super(:address1 => address1,
            :address2 => address2,
            :city => city,
            :state => state,
            :zip => zip,
            :country => country)
{'fraction_non_alphanumeric': 0.10254691689008043, 'fraction_numerical': 0.00871313672922252, 'mean_word_length': 2.8122605363984676, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6049942', 'n_tokens_mistral': 811, 'n_tokens_neox': 789, 'n_words': 184}