Sha256: 553f4ccf107f63afafca1fb40c662091db4197ebe1104050c4023220b98f1540

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true

module Glyptodont
  module Checkers
    # Checks that the age of TODOs is below the specified threshold
    class Age
      def initialize(todos:, threshold:)
        @todos = todos
        @threshold = threshold
      end

      def check
        @age, @reportable_todos = oldest_todos
        message
      end

      def passed?
        todos.empty? || age <= threshold
      end

      private

      attr_reader :todos, :threshold, :age, :reportable_todos

      def message
        if todos.empty?
          "Nothing left to do"
        elsif passed?
          "At #{Glyptodont.pluralize(age, "day")}, TODOs are fresh enough for now"
        else
          "Some TODOs are too stale at #{Glyptodont.pluralize(age, "day")} old:\n" +
            reportable_todos.map { |t| Glyptodont.format_todo(t) }.join("\n")
        end
      end

      def oldest_todos
        todos.group_by { |todo| todo[:age] }
             .max_by { |age, _group| age }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
glyptodont-0.1.0 lib/glyptodont/checkers/age.rb