Class: Bmg::Ordering
- Inherits:
-
Object
- Object
- Bmg::Ordering
- Defined in:
- lib/bmg/support/ordering.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
Instance Method Summary collapse
- #comparator ⇒ Object
-
#initialize(attrs) ⇒ Ordering
constructor
A new instance of Ordering.
Constructor Details
#initialize(attrs) ⇒ Ordering
Returns a new instance of Ordering.
4 5 6 |
# File 'lib/bmg/support/ordering.rb', line 4 def initialize(attrs) @attrs = attrs end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
7 8 9 |
# File 'lib/bmg/support/ordering.rb', line 7 def attrs @attrs end |
Instance Method Details
#comparator ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/bmg/support/ordering.rb', line 9 def comparator ->(t1, t2) { attrs.each do |(attr,direction)| c = t1[attr] <=> t2[attr] return (direction == :desc ? -c : c) unless c==0 end 0 } end |