<commit_before>#!/bin/env ruby
# encoding: utf-8

require "active_migration/transformer/grouped_field_fixed_spelling"
require "active_migration/transformer/dictionary"

class SyscadClientesTransformer
  
  include ActiveMigration::Transformer
  include ApplicationHelper
  
  def initialize(schema)
    super schema
    
    @domain_name = "clientes"
    
    @district_dictionary = ActiveMigration::Transformer::Dictionary.new File.expand_path("../cache/bairros_dictionary.yml", __FILE__)
    @state_dictionary = ActiveMigration::Transformer::Dictionary.new File.expand_path("../cache/estados_dictionary.yml", __FILE__)
    @city_dictionary = ActiveMigration::Transformer::Dictionary.new File.expand_path("../cache/cidades_dictionary.yml", __FILE__)
    
    @ignore_record_error = true
  end
  
  def transform(row)
    row[:notes] = '' if row[:notes].nil?
    
    transform_customer_pj row
    transform_contacts row
    transform_customer row
    transform_ignore_fields row
    
    begin
      create_customer row
    rescue
      if @ignore_record_error
        Rails.logger.error "== Error:\n\n".concat(message_record_error())
      end
    end
    :ignore
  end
  
  def transform_customer(row)
    valida_cnpj
    
    #name is empty?
    if (row[:name].nil? || row[:name].empty?) && ((!row[:name_sec].nil?) && (!row[:name_sec].empty?))
      row[:name] = row[:name_sec]
    end<commit_msg>Validacao CNPJ e External Migration<commit_after>#!/bin/env ruby
# encoding: utf-8

require "active_migration/transformer/grouped_field_fixed_spelling"
require "active_migration/transformer/dictionary"

class SyscadClientesTransformer
  
  include ActiveMigration::Transformer
  include ApplicationHelper
  
  def initialize(schema)
    super schema
    
    @domain_name = "clientes"
    
    @district_dictionary = ActiveMigration::Transformer::Dictionary.new File.expand_path("../cache/bairros_dictionary.yml", __FILE__)
    @state_dictionary = ActiveMigration::Transformer::Dictionary.new File.expand_path("../cache/estados_dictionary.yml", __FILE__)
    @city_dictionary = ActiveMigration::Transformer::Dictionary.new File.expand_path("../cache/cidades_dictionary.yml", __FILE__)
    
    @ignore_record_error = true
  end
  
  def transform(row)
    row[:notes] = '' if row[:notes].nil?
    
    transform_customer_pj row
    transform_contacts row
    transform_customer row
    transform_ignore_fields row
    
    begin
      create_customer row
    rescue
      if @ignore_record_error
        Rails.logger.error "== Error:\n\n".concat(message_record_error())
      end
    end
    :ignore
  end
  
  def transform_customer(row)
    valida_cnpj row
    
    #name is empty?
    if (row[:name].nil? || row[:name].empty?) && ((!row[:name_sec].nil?) && (!row[:name_sec].empty?))
      row[:name] = row[:name_sec]
    end
{'fraction_non_alphanumeric': 0.11173974540311174, 'fraction_numerical': 0.0007072135785007072, 'mean_word_length': 3.8276450511945392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4037007', 'n_tokens_mistral': 896, 'n_tokens_neox': 875, 'n_words': 152}