Class: Priora::Priority

Inherits:
Object
  • Object
show all
Defined in:
lib/priora/priority.rb

Constant Summary collapse

DIRECTION_DESC =
:desc
DIRECTION_ASC =
:asc
DIRECTIONAL_METHODS =
{
    DIRECTION_DESC => :+,
    DIRECTION_ASC => :-
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute:, direction: DIRECTION_DESC) ⇒ Priority

Returns a new instance of Priority.


13
14
15
16
# File 'lib/priora/priority.rb', line 13

def initialize(attribute:, direction: DIRECTION_DESC)
  @attribute = attribute
  @direction = direction
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute


11
12
13
# File 'lib/priora/priority.rb', line 11

def attribute
  @attribute
end

#directionObject (readonly)

Returns the value of attribute direction


11
12
13
# File 'lib/priora/priority.rb', line 11

def direction
  @direction
end

Instance Method Details

#comparable_value_from(object) ⇒ Object


18
19
20
21
22
# File 'lib/priora/priority.rb', line 18

def comparable_value_from(object)
  raw_value = object.send(@attribute)
  numeric_value = numeric_value_from(raw_value)
  directional_value_from(numeric_value)
end