Class: Comparability::Comparators::ValueComparator

Inherits:
Comparability::Comparator show all
Defined in:
lib/comparability/comparators/value_comparator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Comparability::Comparator

#to_proc

Methods included from FactoryMethods

#chain, #create, #natural_order, #prioritize_nil, #reverse

Instance Attribute Details

#nil_value_priorityObject

Returns the value of attribute nil_value_priority.



26
27
28
# File 'lib/comparability/comparators/value_comparator.rb', line 26

def nil_value_priority
  @nil_value_priority
end

Instance Method Details

#compare(me, other) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/comparability/comparators/value_comparator.rb', line 9

def compare(me, other)
  me_value = extract_value(me)
  other_value = extract_other_value(me, other)

  if nil_value_priority
    nil_result = NilComparator.with_nil_priority(nil_value_priority).compare(me_value, other_value)
    return nil_result if nil_result && nil_result.nonzero?
  end

  me_value <=> other_value
end