Class: Believer::OrderBy
- Inherits:
-
Object
- Object
- Believer::OrderBy
- Defined in:
- lib/believer/order_by.rb
Overview
Encapsulates the CQL ORDER BY clause
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
Instance Method Summary collapse
-
#initialize(field, dir = :asc) ⇒ OrderBy
constructor
A new instance of OrderBy.
-
#inverse ⇒ Object
Inverts the direction of the order.
-
#to_cql ⇒ Object
Creates the CQL ORDER BY clause.
Constructor Details
#initialize(field, dir = :asc) ⇒ OrderBy
Returns a new instance of OrderBy.
10 11 12 13 14 15 |
# File 'lib/believer/order_by.rb', line 10 def initialize(field, dir = :asc) raise "Invalid field: #{field}" unless field.is_a?(Symbol) || field.is_a?(String) raise "Direction must be one of (:asc|:desc): #{dir}" unless dir == :asc || dir == :desc @field = field @dir = dir end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
6 7 8 |
# File 'lib/believer/order_by.rb', line 6 def dir @dir end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
6 7 8 |
# File 'lib/believer/order_by.rb', line 6 def field @field end |
Instance Method Details
#inverse ⇒ Object
Inverts the direction of the order
23 24 25 |
# File 'lib/believer/order_by.rb', line 23 def inverse OrderBy.new(@field, @dir == :asc ? :desc : :asc) end |
#to_cql ⇒ Object
Creates the CQL ORDER BY clause
18 19 20 |
# File 'lib/believer/order_by.rb', line 18 def to_cql "ORDER BY #{@field} #{@dir.to_s.upcase}" end |