<commit_before>require 'carmen-rails'

module EffectiveAddressesHelper
  @@use_geocoder = defined?(Geocoder)

  def effective_address_fields(form, method = 'billing', options = {})
    method = (method.to_s.include?('_address') ? method.to_s : "#{method}_address")

    required = (form.object._validators[method.to_sym].any? { |v| v.kind_of?(ActiveRecord::Validations::PresenceValidator) && (v.options[:if].blank? || (v.options[:if].respond_to?(:call) ? f.object.instance_exec(&v.options[:if]) : v.options[:if])) } rescue true)
    use_full_name = form.object._validators[method.to_sym].any? { |v| v.kind_of?(EffectiveAddressFullNamePresenceValidator) }

    address = form.object.send(method) || form.object.addresses.build(:category => method.to_s.gsub('_address', ''))
    effective_address_pre_select(address) if address.new_record?

    opts = {:required => required, :use_full_name => use_full_name, :field_order => [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code]}.merge(options).merge({:f => form, :address => address, :method => method})

    if form.class.name == 'SimpleForm::FormBuilder'
      render :partial => 'effective/addresses/address_fields_simple_form', :locals => opts
    elsif form.class.name == 'Formtastic::FormBuilder'
      render :partial => 'effective/addresses/address_fields_formtastic', :locals => opts
    else
      raise 'Unsupported FormBuilder.  You must use formtastic or simpleform. Sorry.'
    end
  end

  def effective_address_pre_select(address)
    if EffectiveAddresses.pre_selected_country.present?
      address.country = EffectiveAddresses.pre_selected_country
      address.state = EffectiveAddresses.pre_selected_state if (result[0].present? && EffectiveAddresses.pre_selected_state.present?)
    elsif @@use_geocoder
      data = request.location.data
      address.country = data['country_code']
      address.state = data['region_code']
      address.postal_code = data['postal_code']
      address.city = data['city']
    end<commit_msg>Handled new record prefill case where a valid local IP such as 10.1.10.1 was passed, didn't match the dev/test scenario and yielded no location data.<commit_after>require 'carmen-rails'

module EffectiveAddressesHelper
  @@use_geocoder = defined?(Geocoder)

  def effective_address_fields(form, method = 'billing', options = {})
    method = (method.to_s.include?('_address') ? method.to_s : "#{method}_address")

    required = (form.object._validators[method.to_sym].any? { |v| v.kind_of?(ActiveRecord::Validations::PresenceValidator) && (v.options[:if].blank? || (v.options[:if].respond_to?(:call) ? f.object.instance_exec(&v.options[:if]) : v.options[:if])) } rescue true)
    use_full_name = form.object._validators[method.to_sym].any? { |v| v.kind_of?(EffectiveAddressFullNamePresenceValidator) }

    address = form.object.send(method) || form.object.addresses.build(:category => method.to_s.gsub('_address', ''))
    effective_address_pre_select(address) if address.new_record?

    opts = {:required => required, :use_full_name => use_full_name, :field_order => [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code]}.merge(options).merge({:f => form, :address => address, :method => method})

    if form.class.name == 'SimpleForm::FormBuilder'
      render :partial => 'effective/addresses/address_fields_simple_form', :locals => opts
    elsif form.class.name == 'Formtastic::FormBuilder'
      render :partial => 'effective/addresses/address_fields_formtastic', :locals => opts
    else
      raise 'Unsupported FormBuilder.  You must use formtastic or simpleform. Sorry.'
    end
  end

  def effective_address_pre_select(address)
    if EffectiveAddresses.pre_selected_country.present?
      address.country = EffectiveAddresses.pre_selected_country
      address.state = EffectiveAddresses.pre_selected_state if (result[0].present? && EffectiveAddresses.pre_selected_state.present?)
    elsif @@use_geocoder && request.location.present?
      data = request.location.data
      address.country = data['country_code']
      address.state = data['region_code']
      address.postal_code = data['postal_code']
      address.city = data['city']
    end
{'fraction_non_alphanumeric': 0.13835583984837715, 'fraction_numerical': 0.0028429282160625444, 'mean_word_length': 5.014245014245014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3420726', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1307, 'n_words': 238}