<commit_before>module Metacrunch
  module UBPB
    module Transformations
      module MAB2SNR
        class Status < Metacrunch::Transformer::Step

          NEW_STATE    = "A".freeze
          DELETE_STATE = "D".freeze

          def perform
            target.add("control", "status", get_status)
          end

        private

          #
          # @return [String] A for new or updated records, D for deleted records.
          #
          def get_status
            status = NEW_STATE

            # gelöscht -> LDR Position 6 == 'd'
            status = DELETE_STATE if source.controlfield("LDR").at(5) == "d"

            # ausgesondert über Feld 078
            status = DELETE_STATE if source.datafields("078", ind1: "r").subfields("a").values.first == "aus"

            # Standort Detmold unterdrücken
            detmold_locations = source.datafields("LOC").subfields("n").values
            status = DELETE_STATE if detmold_locations.all?{ |l| l == "50" }

            # Interimsaufnahmen unterdrücken
            temp_records = source.datafields("537", ind1: "-", ind2: "1").subfields("a").values
            status = DELETE_STATE if temp_records.any?{ |v| v.downcase!.include? "interimsaufnahme" }

            status
          end

        end
      end
    end
  end
end<commit_msg>Bugfix.<commit_after>module Metacrunch
  module UBPB
    module Transformations
      module MAB2SNR
        class Status < Metacrunch::Transformer::Step

          NEW_STATE    = "A".freeze
          DELETE_STATE = "D".freeze

          def perform
            target.add("control", "status", get_status)
          end

        private

          #
          # @return [String] A for new or updated records, D for deleted records.
          #
          def get_status
            status = NEW_STATE

            # gelöscht -> LDR Position 6 == 'd'
            status = DELETE_STATE if source.controlfield("LDR").at(5) == "d"

            # ausgesondert über Feld 078
            status = DELETE_STATE if source.datafields("078", ind1: "r").subfields("a").values.first == "aus"

            # Standort Detmold unterdrücken
            detmold_locations = source.datafields("LOC").subfields("n").values
            status = DELETE_STATE if detmold_locations.all?{ |l| l == "50" }

            # Interimsaufnahmen unterdrücken
            temp_records = source.datafields("537", ind1: "-", ind2: "1").subfields("a").values
            status = DELETE_STATE if temp_records.any?{ |v| v.downcase.include? "interimsaufnahme" }

            status
          end

        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10388611004232397, 'fraction_numerical': 0.01385148133897653, 'mean_word_length': 1.9147982062780269, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '526095', 'n_tokens_mistral': 804, 'n_tokens_neox': 755, 'n_words': 183}