<commit_before>namespace :selector_reports do

  @minus3months = Time.now - 3.months
  @minus1year = Time.now - 1.year

  def filter_delims(field)
    unless field.nil?
      field = field.gsub(/\|[af]/, '')
      field.gsub(/\|[a]/, '')
      field.gsub(/\|[b-z]/, ' ')
    end
  end

  def lmlo_create(x)
      bibview = x.bib_views.first
      metadata = x.record_metadata
        Lost.create(
          item_number: x.record_num,
          bib_number: bibview.record_num,
          title: bibview.title,
          imprint: filter_delims(bibview.varfield_views.where(marc_tag: '260').first.try(:field_content) || nil),
          isbn: filter_delims((isbn = Array.new; bibview.varfield_views.where(marc_tag: '020').each {|r| isbn << r.field_content}; isbn = isbn.join(','))),
          status: x.item_status_code,
          checkouts: x.checkout_total,
          location: x.location_code,
          note: filter_delims((note = Array.new; x.varfield_views.where("record_type_code = 'i' AND (varfield_type_code = 'x' OR varfield_type_code = 'm')").each {|r| note << r.field_content}; note = note.join(','))),
          call_number: filter_delims(x.item_record_property.call_number),
          volume: x.varfield_views.where("varfield_type_code = 'v'").first.try(:field_content) || nil,
          barcode: x.barcode,
          due_date: x.checkout.try(:due_gmt) || nil,
          last_checkout: x.last_checkout_gmt,
          created_at: x.record_creation_date_gmt,
          updated_at: x.record_metadata.record_last_updated_gmt
          ) 
    puts bibview.title
  end 

  namespace :losts do
    desc "drop losts table"
    task:drop_losts => :environment do
      if ActiveRecord::Base.connection.table_exists? 'losts'
        DatabaseCleaner.clean_with(:truncation, :only => %w[losts])
        else
          Rake::Task['db:migrate'].execute
        end
    end<commit_msg>refactor rake task with collect<commit_after>namespace :selector_reports do

  @minus3months = Time.now - 3.months
  @minus1year = Time.now - 1.year

  def filter_delims(field)
    unless field.nil?
      field = field.gsub(/\|[af]/, '')
      field.gsub(/\|[a]/, '')
      field.gsub(/\|[b-z]/, ' ')
    end
  end

  def lmlo_create(x)
      bibview = x.bib_views.first
      metadata = x.record_metadata
        Lost.create(
          item_number: x.record_num,
          bib_number: bibview.record_num,
          title: bibview.title,
          imprint: filter_delims(bibview.varfield_views.where(marc_tag: '260').first.try(:field_content) || nil),
          isbn: filter_delims(bibview.varfield_views.where(marc_tag: '020').collect {|r| r.field_content}.join(', ')),
          status: x.item_status_code,
          checkouts: x.checkout_total,
          location: x.location_code,
          note: filter_delims(x.varfield_views.where("record_type_code = 'i' AND (varfield_type_code = 'x' OR varfield_type_code = 'm')").collect { |x| x.field_content }.join(', ')),
          call_number: filter_delims(x.item_record_property.call_number),
          volume: x.varfield_views.where("varfield_type_code = 'v'").first.try(:field_content) || nil,
          barcode: x.barcode,
          due_date: x.checkout.try(:due_gmt) || nil,
          last_checkout: x.last_checkout_gmt,
          created_at: x.record_creation_date_gmt,
          updated_at: x.record_metadata.record_last_updated_gmt
          ) 
    puts bibview.title
  end 

  namespace :losts do
    desc "drop losts table"
    task:drop_losts => :environment do
      if ActiveRecord::Base.connection.table_exists? 'losts'
        DatabaseCleaner.clean_with(:truncation, :only => %w[losts])
        else
          Rake::Task['db:migrate'].execute
        end
    end
{'fraction_non_alphanumeric': 0.132829373650108, 'fraction_numerical': 0.005399568034557235, 'mean_word_length': 2.815653964984552, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1320979', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1261, 'n_words': 210}