<commit_before># If certain models need to be processed out in a different way
# (see #default_process) this is a the place for these overrides, e.g.:
#
#  Language: {
#    create: ->(attributes) {
#      Language.insert(attributes)
#    }
#  }
#
# NOTE: in case of :create and :updates must return instance of model as
#       it is going to be validated. :destroy returns nil, because we do not
#       want to be validating non existant records.
# NOTE: takes one argument: the arguments.
#
# Can also mutate attributes for all record operations, e.g.:
#
#  Language: {
#    attributes: ->(attributes) {
#      attributes[:a] = 'b'
#      attributes   # do not forget to return it
#    }
#  }

class TaricImporter < TariffImporter
  PROCESSOR_OVERRIDES = {
      Measure: {
        # Avoid naming conflicts with associations.
        attributes: ->(attributes) {
          attributes['measure_type_id'] = attributes.delete('measure_type')
          attributes['additional_code_id'] = attributes.delete('additional_code')
          attributes['geographical_area_id'] = attributes.delete('geographical_area')
          attributes['additional_code_type_id'] = attributes.delete('additional_code_type')
          attributes
        }
      },
      GoodsNomenclature: {
        update: ->(record) {
          goods_nomenclature = record.klass.filter(record.attributes.slice(*record.primary_key).symbolize_keys).first
          goods_nomenclature.set(record.attributes.except(*record.primary_key).symbolize_keys)
          goods_nomenclature.save
<commit_msg>Improve docs for the TaricImporter::ProcessorOverrides<commit_after># If certain models need to be processed out in a different way
# (see RecordProcessor#default_process) this is a the place for
# these overrides, e.g.:
#
#  Language: {
#    create: ->(attributes) {
#      Language.insert(attributes)
#    }
#  }
#
# NOTE: in case of :create and :updates must return instance of model as
#       it is going to be validated. :destroy returns nil, because we do not
#       want to be validating non existent records.
# NOTE: takes one argument: for attributes it's the attributes
# hash (string based). For create, update, destroy it's the record instance.
#
# Can also mutate attributes for all record operations, e.g.:
#
#  Language: {
#    attributes: ->(attributes) {
#      attributes[:a] = 'b'
#      attributes   # do not forget to return it
#    }
#  }

class TaricImporter < TariffImporter
  PROCESSOR_OVERRIDES = {
      Measure: {
        # Avoid naming conflicts with associations.
        attributes: ->(attributes) {
          attributes['measure_type_id'] = attributes.delete('measure_type')
          attributes['additional_code_id'] = attributes.delete('additional_code')
          attributes['geographical_area_id'] = attributes.delete('geographical_area')
          attributes['additional_code_type_id'] = attributes.delete('additional_code_type')
          attributes
        }
      },
      GoodsNomenclature: {
        update: ->(record) {
          goods_nomenclature = record.klass.filter(record.attributes.slice(*record.primary_key).symbolize_keys).first
          goods_nomenclature.set(record.attributes.except(*record.primary_key).symbolize_keys)
          goods_nomenclature.save

{'fraction_non_alphanumeric': 0.10370143774854695, 'fraction_numerical': 0.0, 'mean_word_length': 3.2913385826771653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '2354231', 'n_tokens_mistral': 937, 'n_tokens_neox': 909, 'n_words': 250}