Class: ROM::CSV::Repository
- Inherits:
-
Repository
- Object
- Repository
- ROM::CSV::Repository
- Defined in:
- lib/rom/csv/repository.rb
Overview
CSV repository interface
Instance Method Summary collapse
-
#[](name) ⇒ Dataset
Return dataset with the given name.
-
#dataset(name) ⇒ Dataset
Register a dataset in the repository.
-
#dataset?(name) ⇒ Boolean
Check if dataset exists.
-
#initialize(path, options = {}) ⇒ Repository
constructor
private
Expect a path to a single csv file which will be registered by rom to the given name or :default as the repository.
Constructor Details
#initialize(path, options = {}) ⇒ Repository
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.
Expect a path to a single csv file which will be registered by rom to the given name or :default as the repository.
Uses CSV.table which passes the following csv options:
-
headers: true
-
converters: numeric
-
header_converters: :symbol
56 57 58 59 |
# File 'lib/rom/csv/repository.rb', line 56 def initialize(path, = {}) @datasets = {} @connection = ::CSV.table(path, ).by_row! end |
Instance Method Details
#[](name) ⇒ Dataset
Return dataset with the given name
67 68 69 |
# File 'lib/rom/csv/repository.rb', line 67 def [](name) datasets[name] end |
#dataset(name) ⇒ Dataset
Register a dataset in the repository
If dataset already exists it will be returned
79 80 81 |
# File 'lib/rom/csv/repository.rb', line 79 def dataset(name) datasets[name] = Dataset.new(connection) end |
#dataset?(name) ⇒ Boolean
Check if dataset exists
88 89 90 |
# File 'lib/rom/csv/repository.rb', line 88 def dataset?(name) datasets.key?(name) end |