Class: Velocity::Instance::QueryResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/acceleration/velocity.rb

Overview

QueryResponse wraps the XML output from a Query#search in an object which provides several convenience methods in addition to exposing the underlying XML document comprising the response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ QueryResponse

Create a new QueryResponse given the response XML from Velocity



398
399
400
# File 'lib/acceleration/velocity.rb', line 398

def initialize(doc)
  @doc = doc
end

Instance Attribute Details

#docObject

A handle on the XML document behind the response



393
394
395
# File 'lib/acceleration/velocity.rb', line 393

def doc
  @doc
end

Instance Method Details

#documentsObject

Retrieve all documents from the query response



412
413
414
415
416
# File 'lib/acceleration/velocity.rb', line 412

def documents
  doc.xpath('/query-results/list/document').collect do |d|
    Document.new d
  end
end

#fileObject

Retrieve the file name of the browse file, a.k.a. v:file.

Pass this as the :file option to Query#browse in order for that method to work properly.



423
424
425
# File 'lib/acceleration/velocity.rb', line 423

def file
  doc.xpath('/query-results/@file').first.value
end

#results?Boolean

Indicates if a query response actually contains documents

Returns:

  • (Boolean)


405
406
407
# File 'lib/acceleration/velocity.rb', line 405

def results?
  !documents.empty?
end