Class Wac::Query

  1. lib/wac/query.rb
Parent: Object

responsible for constructing a query, and returning the io stream for the query, and creating a Result has a session object, input, and options

Methods

public class

  1. new

public instance

  1. data
  2. fetch
  3. fetched?
  4. inspect
  5. query_options
  6. query_uri
  7. result
  8. uri

Included modules

  1. OpenURI

Attributes

input [RW]
options [RW]
session [RW]

Public class methods

new (input, options = {})
[show source]
# File lib/wac/query.rb, line 11
    def initialize(input, options = {})
      @input = input
      @session = options.delete(:session)
      @options = options
    end

Public instance methods

data ()
[show source]
# File lib/wac/query.rb, line 44
    def data
      open(uri).read
    end
fetch ()

go and fetch the result, this is done automaticaly if you ask for the result

[show source]
# File lib/wac/query.rb, line 23
    def fetch
      @result = Result.new(data, :query => self)
    end
fetched? ()

has the result been fetched?

[show source]
# File lib/wac/query.rb, line 18
    def fetched?
      @result ? true : false
    end
inspect ()
[show source]
# File lib/wac/query.rb, line 53
    def inspect
      out = "q: \"#{input}\""
      out << " #{options[:podstate]}" if options[:podstate]
      out << " (assuming #{options[:assumption]})" if options[:assumption]
      out << ", a: #{result.datatypes}" if fetched?
      out
    end
query_options ()

the full set of options used to make this query, including those inherited form the session

[show source]
# File lib/wac/query.rb, line 39
    def query_options
      opts = options.merge(:input => input)
      session ? session.query_options.merge(opts) : opts
    end
query_uri ()

use session query_uri, or Wac.query_uri if no session available

[show source]
# File lib/wac/query.rb, line 49
    def query_uri
      session ? session.query_uri : Wac.query_uri
    end
result ()

the query result

[show source]
# File lib/wac/query.rb, line 28
    def result
      fetch unless fetched?
      @result
    end
uri ()

the uri that this query will issue a get request to

[show source]
# File lib/wac/query.rb, line 34
    def uri
      "#{query_uri}?#{query_options.to_query}"
    end