Class: Ace::Review::Atoms::PriorityFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/review/atoms/priority_filter.rb

Overview

Filters feedback items by priority level with optional range support.

Supports exact matching (“high”) and inclusive range matching (“high+”). Range matching includes the specified priority and all higher priorities.

Priority hierarchy (highest to lowest): critical > high > medium > low

Examples:

Exact matching

PriorityFilter.matches?("high", "high")
#=> true

PriorityFilter.matches?("medium", "high")
#=> false

Range matching with + suffix

PriorityFilter.matches?("high", "medium+")
#=> true (high >= medium)

PriorityFilter.matches?("critical", "medium+")
#=> true (critical >= medium)

PriorityFilter.matches?("low", "medium+")
#=> false (low < medium)

Constant Summary collapse

PRIORITY_ORDER =

Priority levels in descending order (highest first)

{
  "critical" => 4,
  "high" => 3,
  "medium" => 2,
  "low" => 1
}.freeze
VALID_PRIORITIES =
PRIORITY_ORDER.keys.freeze

Class Method Summary collapse

Class Method Details

.matches?(item_priority, filter_string) ⇒ Boolean

Check if an item priority matches a filter string

Examples:

Exact match

PriorityFilter.matches?("high", "high")
#=> true

PriorityFilter.matches?("medium", "high")
#=> false

Range match

PriorityFilter.matches?("critical", "high+")
#=> true

PriorityFilter.matches?("high", "high+")
#=> true

PriorityFilter.matches?("medium", "high+")
#=> false

Parameters:

  • item_priority (String)

    The priority of the item (“critical”, “high”, etc.)

  • filter_string (String)

    The filter string (“high” or “high+”)

Returns:

  • (Boolean)

    True if the item priority matches the filter



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ace/review/atoms/priority_filter.rb', line 92

def self.matches?(item_priority, filter_string)
  return false if item_priority.nil? || filter_string.nil?

  parsed = parse(filter_string)
  return false if parsed.nil?

  item_level = PRIORITY_ORDER[item_priority]
  filter_level = PRIORITY_ORDER[parsed[:priority]]

  # Unknown item priority doesn't match
  return false if item_level.nil?

  if parsed[:inclusive]
    # Range match: item priority must be >= filter priority
    item_level >= filter_level
  else
    # Exact match
    item_priority == parsed[:priority]
  end
end

.parse(filter_string) ⇒ Hash?

Parse a priority filter string into its components

Examples:

Exact match

PriorityFilter.parse("high")
#=> { priority: "high", inclusive: false }

Range match

PriorityFilter.parse("medium+")
#=> { priority: "medium", inclusive: true }

Invalid priority

PriorityFilter.parse("urgent")
#=> nil

Parameters:

  • filter_string (String)

    Priority filter like “medium” or “medium+”

Returns:

  • (Hash, nil)

    Hash with :priority and :inclusive keys, or nil if invalid



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ace/review/atoms/priority_filter.rb', line 57

def self.parse(filter_string)
  return nil if filter_string.nil? || filter_string.empty?

  # Check for + suffix (inclusive range)
  inclusive = filter_string.end_with?("+")
  priority = inclusive ? filter_string.chomp("+") : filter_string

  # Validate priority
  return nil unless VALID_PRIORITIES.include?(priority)

  {priority: priority, inclusive: inclusive}
end