You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: animal_groups_exchanger.rb
    path of file: ./repos/ekylibre/app/exchangers/ekylibre
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

module Ekylibre
  class AnimalGroupsExchanger < ActiveExchanger::Base
    category :animal_farming
    vendor :ekylibre

    def check
      valid = true

      # Check building division presence
      unless building_division = BuildingDivision.first
        w.error 'Need almost one BuildingDivision'
        valid = false
      end

      rows = CSV.read(file, headers: true).delete_if { |r| r[0].blank? }
      w.count = rows.size
      rows.each_with_index do |row, index|
        line_number = index + 2
        prompt = "L#{line_number.to_s.yellow}"
        next if row[0].blank?

        r = OpenStruct.new(
          name: row[0],
          nature: row[1].to_s,
          member_nature: (row[2].blank? ? nil : row[2].to_sym),
          code: row[3],
          minimum_age: (row[4].blank? ? nil : row[4].to_i),
          maximum_age: (row[5].blank? ? nil : row[5].to_i),
          sex: (row[6].blank? ? nil : row[6].to_sym),
          place: (row[7].blank? ? nil : row[7].to_s),
          indicators_at: (row[8].blank? ? Time.zone.today : row[8]).to_datetime,
          indicators: row[9].blank? ? {} : row[9].to_s.strip.split(/[[:space:]]*\;[[:space:]]*/).collect { |i| i.split(/[[:space:]]*\:[[:space:]]*/) }.each_with_object({}) do |i, h|
            h[i.first.strip.downcase.to_sym] = i.second
   
    
    def import
      rows = CSV.read(file, headers: true).delete_if { |r| r[0].blank? }
      w.count = rows.size

      rows.each do |row|
        r = OpenStruct.new(
          name: row[0],
          nature: row[1].to_s,
          member_nature: (row[2].blank? ? nil : row[2].to_sym),
          code: row[3],
          minimum_age: (row[4].blank? ? nil : row[4].to_i),
          maximum_age: (row[5].blank? ? nil : row[5].to_i),
          sex: (row[6].blank? ? nil : row[6].to_sym),
          place: (row[7].blank? ? nil : row[7].to_s),
          indicators_at: (row[8].blank? ? Time.zone.today : row[8]).to_datetime,
          indicators: row[9].blank? ? {} : row[9].to_s.strip.split(/[[:space:]]*\;[[:space:]]*/).collect { |i| i.split(/[[:space:]]*\:[[:space:]]*/) }.each_with_object({}) do |i, h|
            h[i.first.strip.downcase.to_sym] = i.second
            h
          end,
          activity_family_name: row[10].to_s,
          activity_name: row[11].to_s,
          campaign_year: row[12].to_i,
          started_on: Date.parse(row[13].to_s),
          stopped_on: Date.parse(row[14].to_s),
          population_in_production: row[15].to_i
        )

        unless variant = ProductNatureVariant.find_by(work_number: r.nature)
          variant = ProductNatureVariant.import_from_nomenclature(r.nature.to_sym)
        end

        r.member_nature = "#{r.member_nature}_band".to_sym if r.member_nature.to_s =~ /^(fe)?male_young_pig$/
        r.member_nature = :young_rabbit if r.member_nature.to_s =~ /^(fe)?male_young_rabbit$/
        animal_variant = ProductNatureVariant.find_by(work_number: r.member_nature) ||
                         ProductNatureVariant.find_by(reference_name: r.member_nature) ||
                         ProductNatureVariant.import_from_nomenclature(r.member_nature)
        animal_variant ||= ProductNatureVariant.import_from_nomenclature(r.member_nature)

        # get animal default container
        animal_container = BuildingDivision.find_by(work_number: r.place)

        # find or create animal_group
        if animal_group = AnimalGroup.find_by(work_number: r.code)
          animal_group.name = r.name
          animal_group.member_variant ||= animal_variant
          animal_group.initial_container ||= animal_container
          animal_group.default_storage ||= animal_container
          animal_group.save!
        else
          animal_group = AnimalGroup.create!(
            name: r.name,
            work_number: r.code,
            initial_born_at: r.indicators_at,
            initial_population: 1.0,
            variant: variant,
            member_variant: animal_variant,
            initial_container: animal_container,
            default_storage: animal_container
          )
          # create indicators linked to animal group
          r.indicators.each do |indicator, value|
            if indicator.to_sym == :population
              animal_group.move!(value, at: r.indicators_at)
            else
              animal_group.read!(indicator, value, at: r.indicators_at, force: true)
            end
          end
          # animal_group.initial_population = animal_group.population
          animal_group.save!
        end