Class: Velocity::Instance::Query::Sort
- Inherits:
-
Object
- Object
- Velocity::Instance::Query::Sort
- Defined in:
- lib/acceleration/velocity.rb
Overview
This helper provides a programatic way to construct :sort-xpaths
XML for query-search
.
The expected usage of this is to put any Sorts in an array and then Array#join them when setting the :sort-xpaths
parameter of Query#search.
Constant Summary collapse
- VALID_ORDERS =
valid orders
[:ascending, :descending, nil].freeze
Instance Attribute Summary collapse
-
#order ⇒ Object
The order in which it should be sorted.
-
#xpath ⇒ Object
The xpath to the content to be sorted.
Instance Method Summary collapse
-
#initialize(args) ⇒ Sort
constructor
call-seq: new(:order => order, :xpath => xpath).
-
#to_s ⇒ Object
Create an XML string from the Sort object.
Constructor Details
#initialize(args) ⇒ Sort
call-seq:
new(:order => order, :xpath => xpath)
Create a new Sort helper
362 363 364 365 |
# File 'lib/acceleration/velocity.rb', line 362 def initialize(args) @xpath = args[:xpath] @order = args[:order] || VALID_ORDERS.first end |
Instance Attribute Details
#order ⇒ Object
The order in which it should be sorted
353 354 355 |
# File 'lib/acceleration/velocity.rb', line 353 def order @order end |
#xpath ⇒ Object
The xpath to the content to be sorted
350 351 352 |
# File 'lib/acceleration/velocity.rb', line 350 def xpath @xpath end |
Instance Method Details
#to_s ⇒ Object
Create an XML string from the Sort object
368 369 370 371 372 373 374 375 |
# File 'lib/acceleration/velocity.rb', line 368 def to_s sane? builder = Nokogiri::XML::Builder.new do |xml| xml.sort(xpath: xpath, order: order) end # this is necessary to suppress the xml version declaration Nokogiri::XML(builder.to_xml).root.to_xml end |