<commit_before>require 'model/invoiceable'
require 'connector/base'
require 'date'
class Invoicer
  attr_accessor :connector

  def initialize(connector = Connector::Base.new)
    self.connector = connector
  end

  def invoice_company(company)
    company = create_company(company)
    invoice = company.create_invoice
    @connector.post_invoice(invoice).save unless invoice.empty?
    invoice
  end

  def can_post?(company)
    return false if company.yet_in_invoicing_system?
    return true if company.name.nil?
    lookup_available_contact(company).nil?
  end

  def create_company(company)
    merge!(company)
    company = @connector.post_contact(company) if can_post? company
    company.save
    company
  end

  def merge_contact_in_company(company, contact)
    attributes_but_mail = contact.attributes.reject do |key, value|
      key == :email
    end
    company.invoicing_system_email = contact.email
    company.attributes = company.attributes.merge(attributes_but_mail)
  end
  private :merge_contact_in_company

  def lookup_available_contact(company)
    get_available_companies[company.name.downcase]
  end

  def merge!(company)
    contact = lookup_available_contact(company)
    merge_contact_in_company(company, contact) if contact
    company
  end

  def get_available_companies
    unless @companies_indexed_by_name_downcase
      @companies_indexed_by_name_downcase = {}
      @connector.get_contacts.each do |company|
        @companies_indexed_by_name_downcase[company.name.downcase] = company
      end
    end
    @companies_indexed_by_name_downcase
  end
end<commit_msg>keep a fresh posted company, so that posting the same do not occur<commit_after>require 'model/invoiceable'
require 'connector/base'
require 'date'
class Invoicer
  attr_accessor :connector

  def initialize(connector = Connector::Base.new)
    self.connector = connector
  end

  def invoice_company(company)
    company = create_company(company)
    invoice = company.create_invoice
    @connector.post_invoice(invoice).save unless invoice.empty?
    invoice
  end

  def can_post?(company)
    return false if company.yet_in_invoicing_system?
    return true if company.name.nil?
    lookup_available_contact(company).nil?
  end

  def create_company(company)
    merge!(company)
    if can_post? company
      company = @connector.post_contact(company)
      add_posted_company(company)
    end
    company.save
    company
  end

  def merge_contact_in_company(company, contact)
    attributes_but_mail = contact.attributes.reject do |key, value|
      key == :email
    end
    company.invoicing_system_email = contact.email
    company.attributes = company.attributes.merge(attributes_but_mail)
  end
  private :merge_contact_in_company

  def lookup_available_contact(company)
    get_available_companies[company.name.downcase]
  end

  def merge!(company)
    contact = lookup_available_contact(company)
    merge_contact_in_company(company, contact) if contact
    company
  end

  def add_posted_company(company)
    @companies_indexed_by_name_downcase[company.name.downcase] = company
  end
  private :add_posted_company

  def get_available_companies
    unless @companies_indexed_by_name_downcase
      @companies_indexed_by_name_downcase = {}
      @connector.get_contacts.each do |company|
        add_posted_company(company)
      end
    end
    @companies_indexed_by_name_downcase
  end
end
{'fraction_non_alphanumeric': 0.06795547744581136, 'fraction_numerical': 0.0, 'mean_word_length': 4.2057926829268295, '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': '202487', 'n_tokens_mistral': 1077, 'n_tokens_neox': 1037, 'n_words': 213}