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
52
53
# File 'lib/bmg/support/ordering.rb', line 45

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

Instance Attribute Details

#attrsObject (readonly)

Returns the value of attribute attrs.



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

def attrs
  @attrs
end

Instance Method Details

#comparatorObject



56
57
58
# File 'lib/bmg/support/ordering.rb', line 56

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

#to_pairsObject



60
61
62
# File 'lib/bmg/support/ordering.rb', line 60

def to_pairs
  attrs.to_a
end