Class: LibyearRb::SortColumn
- Inherits:
-
Data
- Object
- Data
- LibyearRb::SortColumn
- Defined in:
- lib/libyear_rb/sorter.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
Instance Attribute Details
#direction ⇒ Object (readonly)
Returns the value of attribute direction
4 5 6 |
# File 'lib/libyear_rb/sorter.rb', line 4 def direction @direction end |
#field ⇒ Object (readonly)
Returns the value of attribute field
4 5 6 |
# File 'lib/libyear_rb/sorter.rb', line 4 def field @field end |
Instance Method Details
#compare(a, b) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/libyear_rb/sorter.rb', line 5 def compare(a, b) av = a.public_send(field) bv = b.public_send(field) return 0 if av.nil? && bv.nil? return 1 if av.nil? return -1 if bv.nil? (direction == :desc) ? bv <=> av : av <=> bv end |