Class: Bmg::Ordering::Attributes
- Inherits:
-
Object
- Object
- Bmg::Ordering::Attributes
- Includes:
- Bmg::Ordering
- Defined in:
- lib/bmg/support/ordering.rb
Overview
class Native
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
Instance Method Summary collapse
- #comparator ⇒ Object
-
#initialize(attrs) ⇒ Attributes
constructor
A new instance of Attributes.
- #to_pairs ⇒ Object
Methods included from Bmg::Ordering
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
#attrs ⇒ Object (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
#comparator ⇒ Object
56 57 58 |
# File 'lib/bmg/support/ordering.rb', line 56 def comparator @comparator ||= ->(t1, t2) { compare_attrs(t1, t2) } end |
#to_pairs ⇒ Object
60 61 62 |
# File 'lib/bmg/support/ordering.rb', line 60 def to_pairs attrs.to_a end |