Module: ReferenceComparable

Included in:
Bolton::Reference, ComparableReference, Reference
Defined in:
lib/reference_comparable.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) <=>(rhs)



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/reference_comparable.rb', line 3

def <=> rhs
  return 0.00 unless type == rhs.type
  return 0.00 unless normalize_author(author) == normalize_author(rhs.author)

  result = match_title(rhs) || match_article(rhs) || match_book(rhs)
  year_matches = year_matches? rhs
  pagination_matches = pagination_matches? rhs

  case
  when !result && !year_matches then 0.00
  when !result && year_matches then 0.10
  when result && !year_matches then result - 0.50
  when result && !pagination_matches then result - 0.01
  else result
  end
end