Class: Lutaml::UmlRepository::QueryDSL::Order
- Inherits:
-
Object
- Object
- Lutaml::UmlRepository::QueryDSL::Order
- Defined in:
- lib/lutaml/uml_repository/query_dsl/order.rb
Overview
Order specification for sorting query results
Sorts results based on a specified field and direction. Handles nil values by treating them as empty strings for comparison.
Constant Summary collapse
- VALID_DIRECTIONS =
%i[asc desc].freeze
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
-
#apply(results) ⇒ Array
Apply ordering to results.
-
#initialize(field, direction = :asc) ⇒ Order
constructor
Initialize with field and direction.
Constructor Details
#initialize(field, direction = :asc) ⇒ Order
Initialize with field and direction
28 29 30 31 |
# File 'lib/lutaml/uml_repository/query_dsl/order.rb', line 28 def initialize(field, direction = :asc) @field = field.to_sym @direction = validate_direction(direction) end |
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
21 22 23 |
# File 'lib/lutaml/uml_repository/query_dsl/order.rb', line 21 def direction @direction end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
21 22 23 |
# File 'lib/lutaml/uml_repository/query_dsl/order.rb', line 21 def field @field end |
Instance Method Details
#apply(results) ⇒ Array
Apply ordering to results
37 38 39 40 41 42 43 |
# File 'lib/lutaml/uml_repository/query_dsl/order.rb', line 37 def apply(results) sorted = results.sort_by do |obj| extract_sort_value(obj) end @direction == :desc ? sorted.reverse : sorted end |