Class: RosettAi::Composition::PrioritySorter

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/composition/priority_sorter.rb

Overview

Sorts rules by priority within their scope. Lower priority numbers are higher importance (1 = most important). Equal-priority rules within the same scope are ordered by behaviour name alphabetically for deterministic output.

Instance Method Summary collapse

Instance Method Details

#sort_rules(rules) ⇒ Array<Hash>

Sorts an array of annotated rules by scope weight, then priority, then behaviour name.

Parameters:

  • rules (Array<Hash>)

    rules with :scope_weight, :priority, :behaviour_name keys

Returns:

  • (Array<Hash>)

    sorted rules (stable, deterministic)



18
19
20
21
22
23
24
25
26
# File 'lib/rosett_ai/composition/priority_sorter.rb', line 18

def sort_rules(rules)
  rules.sort_by do |rule|
    [
      -(rule[:scope_weight] || 0), # higher scope weight first (negate for ascending sort)
      rule[:priority] || 50,        # lower priority number first
      rule[:behaviour_name].to_s    # alphabetical tie-break
    ]
  end
end