<commit_before>class Juice < ApplicationRecord
  has_many :juice_produce, dependent: :destroy
  has_many :produce, through: :juice_produce
  belongs_to :user
  #accepts_nested_attributes_for :produce, :juice_produce, reject_if: proc { |attributes| attributes[:quantity].blank? }, allow_destroy: true
  validates :name, presence: true
  validates :name, uniqueness: true

  def produce_attributes=(produce_attributes)
    produce_attributes.values.each do |produce_attribute|
      if !produce_attribute[:name].empty?
        if produce_attribute[:name].numeric?
          prod = Produce.find(produce_attribute[:name])
        else
          prod = Produce.find_or_create_by(name: produce_attribute[:name])
        end
        if !produce_attribute[:juice_produce_attributes].values.first[:quantity].empty?
          juice_prod = self.juice_produce.find_or_create_by(produce_id: prod.id)
          juice_prod.quantity =  produce_attribute[:juice_produce_attributes].values.first[:quantity]
          juice_prod.save!
        end
      end
    end
  end

  # def produce_attributes?(produce_attributes)
  #   pa = ""
  #   produce_attributes.values.each do |produce_attribute|
  #     pa << produce_attribute[:name]
  #   end
  #   !pa.empty?
  # end

  def self.juices_with_produce(params)
    joins(:juice_produce).where("produce_id =?", params).order(:name)
  end

  def self.sorted
    self.all.sort_by {|juice| juice.name}
  end
end
<commit_msg>added previous and next methods to Juice class for handling pagination<commit_after>class Juice < ApplicationRecord
  has_many :juice_produce, dependent: :destroy
  has_many :produce, through: :juice_produce
  belongs_to :user
  #accepts_nested_attributes_for :produce, :juice_produce, reject_if: proc { |attributes| attributes[:quantity].blank? }, allow_destroy: true
  validates :name, presence: true
  validates :name, uniqueness: true

  def produce_attributes=(produce_attributes)
    produce_attributes.values.each do |produce_attribute|
      if !produce_attribute[:name].empty?
        if produce_attribute[:name].numeric?
          prod = Produce.find(produce_attribute[:name])
        else
          prod = Produce.find_or_create_by(name: produce_attribute[:name])
        end
        if !produce_attribute[:juice_produce_attributes].values.first[:quantity].empty?
          juice_prod = self.juice_produce.find_or_create_by(produce_id: prod.id)
          juice_prod.quantity =  produce_attribute[:juice_produce_attributes].values.first[:quantity]
          juice_prod.save!
        end
      end
    end
  end

  def next
    Juice.where("id > ?", id).limit(1).first
  end

  def prev
    Juice.where("id < ?", id).limit(1).first
  end

  # def produce_attributes?(produce_attributes)
  #   pa = ""
  #   produce_attributes.values.each do |produce_attribute|
  #     pa << produce_attribute[:name]
  #   end
  #   !pa.empty?
  # end

  def self.juices_with_produce(params)
    joins(:juice_produce).where("produce_id =?", params).order(:name)
  end

  def self.sorted
    self.all.sort_by {|juice| juice.name}
  end
end

{'fraction_non_alphanumeric': 0.10522897044494967, 'fraction_numerical': 0.0006495615459564793, 'mean_word_length': 3.7604327666151467, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 4, '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': '2804741', 'n_tokens_mistral': 1003, 'n_tokens_neox': 996, 'n_words': 182}