class Factual::Query::Table

Constants

DEFAULT_LIMIT
VALID_PARAMS

Public Class Methods

new(api, path, params = {}) click to toggle source
Calls superclass method Factual::Query::Base::new
# File lib/factual/query/table.rb, line 13
def initialize(api, path, params = {})
  @path = path
  @action = :read
  super(api, params)
end

Public Instance Methods

page(page_number, paging_options = {}) click to toggle source
# File lib/factual/query/table.rb, line 35
def page(page_number, paging_options = {})
  limit = (paging_options[:per] || paging_options["per"] || DEFAULT_LIMIT).to_i
  limit = DEFAULT_LIMIT if limit < 1

  page_number = page_number.to_i
  page_number = 1 if page_number < 1

  offset = (page_number - 1) * limit
  Table.new(@api, @path, @params.merge(:limit => limit, :offset => offset))
end
row(factual_id) click to toggle source
# File lib/factual/query/table.rb, line 46
def row(factual_id)
  @path += "/#{factual_id}"
  @params = {}
  return self.first
end
sort_asc(*args) click to toggle source
# File lib/factual/query/table.rb, line 25
def sort_asc(*args)
  columns = args.map { |column| "#{column}" }
  Table.new(@api, @path, @params.merge(:sort => columns.join(',')))
end
sort_desc(*args) click to toggle source
# File lib/factual/query/table.rb, line 30
def sort_desc(*args)
  columns = args.map { |column| "#{column}:desc" }
  Table.new(@api, @path, @params.merge(:sort => columns.join(',')))
end