<commit_before>class NomenclatureChange::Merge < NomenclatureChange
  STEPS = [:inputs, :outputs, :children, :names, :distribution, :legislation, :notes, :summary]
  STATUSES = ['new', 'submitted'] + STEPS.map(&:to_s)
  build_basic_dictionary(*STATUSES)
  attr_accessible :inputs_attributes, :output_attributes
  has_many :inputs, :inverse_of => :nomenclature_change,
    :class_name => NomenclatureChange::Input,
    :foreign_key => :nomenclature_change_id,
    :dependent => :destroy
  has_one :output, :inverse_of => :nomenclature_change,
    :class_name => NomenclatureChange::Output,
    :foreign_key => :nomenclature_change_id,
    :dependent => :destroy
  accepts_nested_attributes_for :inputs, :allow_destroy => true
  accepts_nested_attributes_for :output, :allow_destroy => true

  validates :status, inclusion: {
    in: STATUSES,
    message: "%{value} is not a valid status"
  }
  validate :required_inputs, if: :inputs_or_submitting?
  validate :required_outputs, if: :outputs_or_submitting?
  validate :required_ranks, if: :outputs_or_submitting?

  def required_inputs
    if inputs.size < 2
      errors.add(:inputs, "Must have at least two inputs")
      return false
    end
  end

  def required_outputs
    if output.blank?
      errors.add(:output, "Must have one output")
      return false
    end
  end

  def required_ranks
    if !(inputs.map{ |i| i.new_rank.try(:name) || i.taxon_concept.try(:rank).try(:name) }.
      uniq - [output.try(:taxon_concept).try(:rank).try(:name)]).empty?
      errors.add(:outputs, "Must be at same rank as inputs")
      return false
    end<commit_msg>Changed required_ranks to check if the inputs' ranks include the output rank<commit_after>class NomenclatureChange::Merge < NomenclatureChange
  STEPS = [:inputs, :outputs, :children, :names, :distribution, :legislation, :notes, :summary]
  STATUSES = ['new', 'submitted'] + STEPS.map(&:to_s)
  build_basic_dictionary(*STATUSES)
  attr_accessible :inputs_attributes, :output_attributes
  has_many :inputs, :inverse_of => :nomenclature_change,
    :class_name => NomenclatureChange::Input,
    :foreign_key => :nomenclature_change_id,
    :dependent => :destroy
  has_one :output, :inverse_of => :nomenclature_change,
    :class_name => NomenclatureChange::Output,
    :foreign_key => :nomenclature_change_id,
    :dependent => :destroy
  accepts_nested_attributes_for :inputs, :allow_destroy => true
  accepts_nested_attributes_for :output, :allow_destroy => true

  validates :status, inclusion: {
    in: STATUSES,
    message: "%{value} is not a valid status"
  }
  validate :required_inputs, if: :inputs_or_submitting?
  validate :required_outputs, if: :outputs_or_submitting?
  validate :required_ranks, if: :outputs_or_submitting?

  def required_inputs
    if inputs.size < 2
      errors.add(:inputs, "Must have at least two inputs")
      return false
    end
  end

  def required_outputs
    if output.blank?
      errors.add(:output, "Must have one output")
      return false
    end
  end

  def required_ranks
    if !(inputs.map{ |i| i.taxon_concept.try(:rank).try(:name) }.
         include?(output.try(:taxon_concept).try(:rank).try(:name)))
      errors.add(:outputs, "Must be at same rank as inputs")
      return false
    end
{'fraction_non_alphanumeric': 0.11598649892605094, 'fraction_numerical': 0.000613685179502915, 'mean_word_length': 4.442404006677796, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '4809362', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1016, 'n_words': 250}