<commit_before>class CreateOrganizationFromArray

  def initialize(row, mappings)
    @row = row
    @mappings = mappings
  end

  def call(validate)
    check_columns_in
    return nil if @row[@mappings[:date_removed]]
    return nil if Organization.find_by_name(organization_name)

    org = build_organization(organization_name)

    org.save! validate: validate
    org
  end

  private
  def organization_name
    @organization_name ||= FirstCapitalsHumanizer.call(@row[@mappings[:name]])
  end

  def check_columns_in
    @mappings.each_value do |column_name|
      unless @row.header?(column_name)
        raise CSV::MalformedCSVError, "No expected column with name #{column_name} in CSV file"
      end
    end
  end

  def build_organization(organization_name)
    address = Address.new(@row[@mappings[:address]]).parse
    org = Organization.new({
      name:organization_name, 
      address: FirstCapitalsHumanizer.call(address[:address]),<commit_msg>Add specs for CreateOrganizationFromArray service class<commit_after>class CreateOrganizationFromArray

  def initialize(row, mappings)
    @row = row
    @mappings = mappings
  end

  def call(validate)
    check_columns_in
    return nil if @row[@mappings[:date_removed]]
    return nil if Organization.find_by_name(organization_name)

    org = build_organization

    org.save! validate: validate
    org
  end

  private
  def organization_name
    @organization_name ||= FirstCapitalsHumanizer.call(@row[@mappings[:name]])
  end

  def check_columns_in
    @mappings.each_value do |column_name|
      unless @row.header?(column_name)
        raise CSV::MalformedCSVError, "No expected column with name #{column_name} in CSV file"
      end
    end
  end

  def build_organization_from_array
    address = Address.new(@row[@mappings[:address]]).parse
    org = Organization.new({
      name:organization_name, 
      address: FirstCapitalsHumanizer.call(address[:address]),
{'fraction_non_alphanumeric': 0.08758371973209686, 'fraction_numerical': 0.0, 'mean_word_length': 4.0310880829015545, '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': '2263404', 'n_tokens_mistral': 599, 'n_tokens_neox': 563, 'n_words': 132}