Class: Veritable::Table
- Inherits:
-
Object
- Object
- Veritable::Table
- Includes:
- VeritableResource
- Defined in:
- lib/veritable/api.rb
Overview
Represents the resources associated with a single table
Attributes
-
_id
– the unique String id of the table -
description
– the String description of the table
Methods
-
delete
– deletes the associated table resource -
row
– gets a row of the table by its unique id -
rows
– gets a Veritable::Cursor over the collection of rows in the table -
upload_row
– uploads a new row to the table -
batch_upload_rows
– batch uploads multiple rows to the table -
delete_row
– deletes a row from the table by its unique id -
batch_delete_rows
– batch deletes multiple rows from the table -
analyses
– gets a Veritable::Cursor over the collection of analyses of the table -
analysis
– gets a single analysis of the table by its unique id -
create_analysis
– creates a new analysis of the table -
delete_analysis
– deletes an analysis of the table by its unique id -
has_analysis?
– checks if the table has an analysis with the given id
See also: dev.priorknowledge.com/docs/client/ruby
Instance Method Summary collapse
-
#_id ⇒ Object
The String unique id of the table resources.
-
#analyses(opts = {'start' => nil, 'limit' => nil}) ⇒ Object
Gets a cursor for the analysis collection.
-
#analysis(analysis_id) ⇒ Object
Gets an analysis by its unique id.
-
#batch_delete_rows(rows, per_page = 100) ⇒ Object
Batch deletes a list of rows from the table.
-
#batch_upload_rows(rows, per_page = 100) ⇒ Object
Batch uploads multiple rows to the table.
-
#create_analysis(schema, analysis_id = nil, description = "", force = false, analysis_type = "veritable") ⇒ Object
Creates a new analysis.
-
#delete ⇒ Object
Deletes the table.
-
#delete_analysis(analysis_id) ⇒ Object
Deletes an analysis by its unique id.
-
#delete_row(row_id) ⇒ Object
Deletes a row from the table.
-
#description ⇒ Object
The String description of the table resource.
-
#has_analysis?(analysis_id) ⇒ Boolean
Checks if an analysis with the given unique id exists.
-
#inspect ⇒ Object
Returns a string representation of the table resource.
- #rest_delete ⇒ Object
-
#row(row_id) ⇒ Object
Gets a row by its unique id.
-
#rows(opts = {'start' => nil, 'limit' => nil}) ⇒ Object
Gets a cursor for the row collection.
-
#to_s ⇒ Object
Returns a string representation of the table resource.
-
#upload_row(row) ⇒ Object
Uploads a new row to the table.
Methods included from Connection
#get, #initialize, #post, #put, #request
Methods included from VeritableObject
Instance Method Details
#_id ⇒ Object
The String unique id of the table resources
390 |
# File 'lib/veritable/api.rb', line 390 def _id; @doc['_id']; end |
#analyses(opts = {'start' => nil, 'limit' => nil}) ⇒ Object
Gets a cursor for the analysis collection
Arguments
-
opts
A Hash optionally containing the keys-
"start"
– the analysis id from which the cursor should begin returning results. Defaults tonil
, in which case the cursor will return result starting with the lexicographically first analysis id. -
"limit"
– the total number of results to return (must be a Fixnum). Defaults tonil
, in which case the number of results returned will not be limited.
-
Returns
A Veritable::Cursor. The cursor will return Veritable::Analysis objects, in lexicographic order of their unique ids.
See also: dev.priorknowledge.com/docs/client/ruby
298 299 300 301 302 |
# File 'lib/veritable/api.rb', line 298 def analyses(opts={'start' => nil, 'limit' => nil}) Cursor.new({'collection' => link('analyses'), 'start' => opts['start'], 'limit' => opts['limit']}.update(@opts)) {|x| Analysis.new(@opts, x)} end |
#analysis(analysis_id) ⇒ Object
Gets an analysis by its unique id
Arguments
-
analysis_id
– the unique id of the analysis to retrieve
Returns
A new Veritable::Analysis
See also: dev.priorknowledge.com/docs/client/ruby
285 |
# File 'lib/veritable/api.rb', line 285 def analysis(analysis_id); Analysis.new(@opts, get("#{link('analyses')}/#{analysis_id}")); end |
#batch_delete_rows(rows, per_page = 100) ⇒ Object
Batch deletes a list of rows from the table
Arguments
-
rows
– an Enumerator over row data Hashes, each of which represents a row of the table. Each row must contain the key"_id"
, whose value must be a String containing only alphanumeric characters, underscores, and hyphens, and must be unique in the table. Any other keys will be ignored. -
per_page
– optionally controls the number of rows to delete in each batch. Defaults to100
.
Returns
nil
on success.
See also: dev.priorknowledge.com/docs/client/ruby
266 267 268 269 270 271 272 273 274 |
# File 'lib/veritable/api.rb', line 266 def batch_delete_rows(rows, per_page=100) begin batch_modify_rows('delete', rows, per_page) rescue VeritableError => e if (not e.respond_to?(:http_code)) or (not (e.http_code == "404 Resource Not Found")) raise e end end end |
#batch_upload_rows(rows, per_page = 100) ⇒ Object
Batch uploads multiple rows to the table
Arguments
-
rows
– an Enumerator over row data Hashes, each of which represents a row of the table. Each row must contain the key"_id"
, whose value must be a String containing only alphanumeric characters, underscores, and hyphens, and must be unique in the table. -
per_page
– optionally controls the number of rows to upload in each batch. Defaults to100
.
Returns
nil
on success.
See also: dev.priorknowledge.com/docs/client/ruby
243 |
# File 'lib/veritable/api.rb', line 243 def batch_upload_rows(rows, per_page=100); batch_modify_rows('put', rows, per_page); end |
#create_analysis(schema, analysis_id = nil, description = "", force = false, analysis_type = "veritable") ⇒ Object
Creates a new analysis
Arguments
-
schema
– a schema describing the analysis to perform. Must be a Veritable::Schema object or a Hash of the form:{'col_1': {type: 'datatype'}, 'col_2': {type: 'datatype'}, ...}
where the specified datatype for each column is one of ['real', 'boolean', 'categorical', 'count']
and is valid for the column.
-
+analysis_id – the unique String id of the new analysis. Must contain only alphanumeric characters, underscores, and dashes. Note that underscores and dashes are not permitted as the first character of an
analysis_id
. Default isnil
, in which case a new id will be automatically generated. -
description
– a String describing the analysis. Default is''
. -
force
– if true, will overwrite any existing analysis with the same id. Default isfalse
. -
analysis_type
– defaults to, and must be equal to,"veritable"
.
Raises
A Veritable::VeritableError if force
is not true and there is an existing table with the same id.
Returns
A Veritable::Table
See also: dev.priorknowledge.com/docs/client/ruby
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 |
# File 'lib/veritable/api.rb', line 333 def create_analysis(schema, analysis_id=nil, description="", force=false, analysis_type="veritable") if analysis_type != "veritable" if analysis_type.respond_to? :to_s raise VeritableError.new("Invalid analysis type #{analysis_type}.") else raise VeritableError.new("Invalid analysis type.") end end if analysis_id.nil? autogen = true analysis_id = Util.make_analysis_id else autogen = false Util.check_id analysis_id end if has_analysis? analysis_id if autogen return create_analysis(nil, description, false) end if ! force raise VeritableError.new("Couldn't create table -- table with id #{analysis_id} already exists.") else delete_analysis analysis_id end end doc = post(link('analyses'), {:_id => analysis_id, :description => description, :type => analysis_type, :schema => schema}) Analysis.new(@opts, doc) end |
#delete ⇒ Object
Deletes the table
Returns
nil
on success. Succeeds silently if the resource has already been deleted.
See also: dev.priorknowledge.com/docs/client/ruby
185 |
# File 'lib/veritable/api.rb', line 185 def delete; rest_delete(link('self')); end |
#delete_analysis(analysis_id) ⇒ Object
Deletes an analysis by its unique id
Arguments
-
analysis_id
– the unique String id of the analysis to delete
Returns
nil
on success. Succeeds silently if the analysis does not exist.
See also: dev.priorknowledge.com/docs/client/ruby
313 |
# File 'lib/veritable/api.rb', line 313 def delete_analysis(analysis_id); rest_delete("#{link('analyses')}/#{analysis_id}"); nil; end |
#delete_row(row_id) ⇒ Object
Deletes a row from the table
Arguments
-
row_id
– the unique String id of the row to delete
Returns
nil
on success. Succeeds silently if the row does not exist in the table.
See also: dev.priorknowledge.com/docs/client/ruby
254 |
# File 'lib/veritable/api.rb', line 254 def delete_row(row_id); rest_delete("#{link('rows')}/#{row_id}"); nil; end |
#description ⇒ Object
The String description of the table resource
393 |
# File 'lib/veritable/api.rb', line 393 def description; @doc['description']; end |
#has_analysis?(analysis_id) ⇒ Boolean
Checks if an analysis with the given unique id exists
Arguments
-
analysis_id
— the unique id of the table to check
Returns
true
or false
, as appropriate.
See also: dev.priorknowledge.com/docs/client/ruby
373 374 375 376 377 378 379 380 381 |
# File 'lib/veritable/api.rb', line 373 def has_analysis?(analysis_id) begin analysis analysis_id rescue false else true end end |
#inspect ⇒ Object
Returns a string representation of the table resource
384 |
# File 'lib/veritable/api.rb', line 384 def inspect; to_s; end |
#rest_delete ⇒ Object
177 |
# File 'lib/veritable/api.rb', line 177 alias :rest_delete :delete |
#row(row_id) ⇒ Object
Gets a row by its unique id
Arguments
row_id
— the unique id of the row to retrieve
Returns
A Hash representing the row, whose keys are column ids as Strings and whose values are data cells.
See also: dev.priorknowledge.com/docs/client/ruby
196 |
# File 'lib/veritable/api.rb', line 196 def row(row_id); get("#{link('rows')}/#{row_id}"); end |
#rows(opts = {'start' => nil, 'limit' => nil}) ⇒ Object
Gets a cursor for the row collection
Arguments
-
opts
A Hash optionally containing the keys-
"start"
– the row id from which the cursor should begin returning results. Defaults tonil
, in which case the cursor will return result starting with the lexicographically first table id. -
"limit"
– the total number of results to return (must be a Fixnum). Defaults tonil
, in which case the number of results returned will not be limited.
-
Returns
A Veritable::Cursor. The cursor will return Hashes representing the rows, in lexicographic order of their unique ids.
See also: dev.priorknowledge.com/docs/client/ruby
209 210 211 212 213 |
# File 'lib/veritable/api.rb', line 209 def rows(opts={'start' => nil, 'limit' => nil}) Cursor.new({'collection' => link('rows'), 'start' => opts['start'], 'limit' => opts['limit']}.update(@opts)) end |
#to_s ⇒ Object
Returns a string representation of the table resource
387 |
# File 'lib/veritable/api.rb', line 387 def to_s; "#<Veritable::Table _id='#{_id}'>"; end |
#upload_row(row) ⇒ Object
Uploads a new row to the table
Arguments
-
row
– a Hash repreenting the data in the row, whose keys are column ids as Strings. Must contain the key"_id"
, whose value must be a String containing only alphanumeric characters, underscores, and hyphens, and must be unique in the table.
Raises
A Veritable::VeritableError if the row Hash is missing the "_id"
field or is improperly formed.
Returns
nil
on success.
See also: dev.priorknowledge.com/docs/client/ruby
227 228 229 230 231 |
# File 'lib/veritable/api.rb', line 227 def upload_row(row) Util.check_row row put("#{link('rows')}/#{row['_id']}", row) nil end |