Class: TableQuery::Table

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

Overview

Table is a class for loading table data/schema files and providing interfaces for query.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Table

Create a new table.

Parameters:

  • path (String)

    table data file path

  • options (Hash) (defaults to: {})

    table options



23
24
25
26
27
28
29
# File 'lib/table-query/table.rb', line 23

def initialize(path, options={})
  @path = path
  @csv = CSV.read(path)

  eval_schema_file
  setup_query_schemas
end

Instance Attribute Details

#csvObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



15
16
17
# File 'lib/table-query/table.rb', line 15

def csv
  @csv
end

#query_schemasObject (readonly)

table query schema list



12
13
14
# File 'lib/table-query/table.rb', line 12

def query_schemas
  @query_schemas
end

#table_schemaObject (readonly)

table schema



9
10
11
# File 'lib/table-query/table.rb', line 9

def table_schema
  @table_schema
end

#typesObject (readonly)

table field type list



6
7
8
# File 'lib/table-query/table.rb', line 6

def types
  @types
end

Instance Method Details

#schema_pathString

Return schema filename.

Returns:

  • (String)

    schema filename



35
36
37
38
# File 'lib/table-query/table.rb', line 35

def schema_path
  name = "%s-schema.rb" % File.basename(@path, ".*")
  File.join(File.dirname(@path), name)
end