demarches-normaliennes/app/models/sorted_column.rb

28 lines
654 B
Ruby
Raw Normal View History

2024-09-23 10:35:00 +02:00
# frozen_string_literal: true
class SortedColumn
# include validations to enable procedure_presentation.validate_associate,
# which enforces the deserialization of columns in the sorted_column attribute
# and raises an error if a column is not found
include ActiveModel::Validations
2024-09-26 17:18:43 +02:00
attr_reader :column, :order
2024-09-23 10:35:00 +02:00
def initialize(column:, order:)
@column = column
@order = order
end
def ascending? = @order == 'asc'
def opposite_order = ascending? ? 'desc' : 'asc'
2024-09-23 10:35:00 +02:00
def ==(other)
other&.column == column && other.order == order
end
def sort_by_notifications?
@column.notifications? && @order == 'desc'
end
2024-09-23 10:35:00 +02:00
end