Class: Factual::Query::Table

Inherits:
Base
  • Object
show all
Defined in:
lib/factual/query/table.rb

Constant Summary collapse

DEFAULT_LIMIT =
20
VALID_PARAMS =
[
  :filters, :search, :geo, 
  :sort, :select, 
  :limit, :offset, 
  :include_count
]

Instance Attribute Summary

Attributes inherited from Base

#action, #params, #path

Instance Method Summary collapse

Methods inherited from Base

#[], #each, #full_path, #last, #populate, #rows, #schema, #total_count

Constructor Details

#initialize(api, path, params = {}) ⇒ Table

Returns a new instance of Table.



14
15
16
17
18
# File 'lib/factual/query/table.rb', line 14

def initialize(api, path, params = {})
  @path = path
  @action = :read
  super(api, params)
end

Instance Method Details

#page(page_number, paging_options = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/factual/query/table.rb', line 36

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

#sort_asc(*args) ⇒ Object



26
27
28
29
# File 'lib/factual/query/table.rb', line 26

def sort_asc(*args)
  columns = args.map { |column| "#{column}" }
  Table.new(@api, @path, @params.merge(:sort => columns.join(',')))
end

#sort_desc(*args) ⇒ Object



31
32
33
34
# File 'lib/factual/query/table.rb', line 31

def sort_desc(*args)
  columns = args.map { |column| "#{column}:desc" }
  Table.new(@api, @path, @params.merge(:sort => columns.join(',')))
end