Follow the Brass

lib/case_classifier.rb

22 lines · ruby

Project files
# frozen_string_literal: true

require_relative "classification"

class CaseClassifier
  def initialize(expected_caliber:)
    @expected_caliber = expected_caliber
  end

  def classify(items)
    brass, foreign = items.partition { |item| item.respond_to?(:caliber) }
    accepted, wrong_context = brass.partition { |item| expected?(item) }

    Classification.new(accepted:, wrong_context:, foreign:)
  end

  private

  def expected?(item)
    item.caliber == @expected_caliber
  end
end

Read along in the manual: The Reloading Lab · Download the project (zip)