Class: Factual::Query::Base

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/factual/query/base.rb

Direct Known Subclasses

Facets, Match, Resolve, Table

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api, params) ⇒ Base

Returns a new instance of Base.



6
7
8
9
# File 'lib/factual/query/base.rb', line 6

def initialize(api, params)
  @api = api
  @params = params
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



11
12
13
# File 'lib/factual/query/base.rb', line 11

def action
  @action
end

#paramsObject (readonly)

Returns the value of attribute params.



11
12
13
# File 'lib/factual/query/base.rb', line 11

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/factual/query/base.rb', line 11

def path
  @path
end

Instance Method Details

#[](index) ⇒ Object



21
22
23
# File 'lib/factual/query/base.rb', line 21

def [](index)
  rows[index]
end

#dataObject



25
26
27
# File 'lib/factual/query/base.rb', line 25

def data
  response["data"]
end

#each(&block) ⇒ Object



13
14
15
# File 'lib/factual/query/base.rb', line 13

def each(&block)
  rows.each { |row| block.call(row) }
end

#full_pathObject

TODO move to Multiable module, and support multi writes



43
44
45
# File 'lib/factual/query/base.rb', line 43

def full_path
  @api.full_path(@action, @path, @params)
end

#lastObject



17
18
19
# File 'lib/factual/query/base.rb', line 17

def last
  rows.last
end

#populate(query_response) ⇒ Object



47
48
49
# File 'lib/factual/query/base.rb', line 47

def populate(query_response)
  @response = query_response
end

#rowsObject



29
30
31
# File 'lib/factual/query/base.rb', line 29

def rows
  data
end

#schemaObject



38
39
40
# File 'lib/factual/query/base.rb', line 38

def schema
  @schema ||= @api.schema(self)
end

#total_countObject



33
34
35
36
# File 'lib/factual/query/base.rb', line 33

def total_count
  resp = @api.get(self, :include_count => true, :limit => 1)
  resp["total_row_count"]
end