Module: Dphil::Refinements::NaturalSort
- Defined in:
- lib/dphil/refinements/natural_sort.rb
Class Method Summary collapse
-
.grouped_compare(a, b) ⇒ Object
rubocop:disable CyclomaticComplexity.
Class Method Details
.grouped_compare(a, b) ⇒ Object
rubocop:disable CyclomaticComplexity
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dphil/refinements/natural_sort.rb', line 27 def grouped_compare(a, b) # rubocop:disable CyclomaticComplexity a = a&.scan(CMP_REGEX) b = b&.scan(CMP_REGEX) return if a.blank? || b.blank? ret = nil [a.size, b.size].max.times do |index| a_cmp = coerce_chunk(a[index]) || (return -1) b_cmp = coerce_chunk(b[index]) || (return 1) ret = a_cmp <=> b_cmp || (a.is_a?(Integer) && -1 || b.is_a?(Integer) && 1) return ret unless ret == 0 # rubocop:disable NumericPredicate end ret end |