Class: Hocon::Impl::SimpleConfigObject::RenderComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/hocon/impl/simple_config_object.rb

Class Method Summary collapse

Class Method Details

.all_digits?(s) ⇒ Boolean

Returns:

  • (Boolean)


391
392
393
# File 'lib/hocon/impl/simple_config_object.rb', line 391

def self.all_digits?(s)
  s =~ /^\d+$/
end

.sort(arr) ⇒ Object

This is supposed to sort numbers before strings, and sort the numbers numerically. The point is to make objects which are really list-like (numeric indices) appear in order.



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/hocon/impl/simple_config_object.rb', line 399

def self.sort(arr)
  arr.sort do |a, b|
    a_digits = all_digits?(a)
    b_digits = all_digits?(b)
    if a_digits && b_digits
      Integer(a) <=> Integer(b)
    elsif a_digits
      -1
    elsif b_digits
      1
    else
      a <=> b
    end
  end
end