Class: Bmg::Ordering::Attributes

Inherits:
Object
  • Object
show all
Includes:
Bmg::Ordering
Defined in:
lib/bmg/support/ordering.rb

Overview

class Native

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bmg::Ordering

#call, #map, new, #to_a

Constructor Details

#initialize(attrs) ⇒ Attributes

Returns a new instance of Attributes.



45
46
47
48
49
50
51
# File 'lib/bmg/support/ordering.rb', line 45

def initialize(attrs)
  @attrs = if attrs.empty?
    []
  else
    attrs.map{|a| a.is_a?(Symbol) ? [a, :asc] : a }
  end
end

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



52
53
54
# File 'lib/bmg/support/ordering.rb', line 52

def attrs
  @attrs
end

Instance Method Details

#comparatorObject



54
55
56
# File 'lib/bmg/support/ordering.rb', line 54

def comparator
  @comparator ||= ->(t1, t2) { compare_attrs(t1, t2) }
end

#to_pairsObject



58
59
60
# File 'lib/bmg/support/ordering.rb', line 58

def to_pairs
  attrs.to_a
end