Class: NcsNavigator::Warehouse::Transformers::MdesCsv::TableReader
- Inherits:
-
Object
- Object
- NcsNavigator::Warehouse::Transformers::MdesCsv::TableReader
- Includes:
- Enumerable
- Defined in:
- lib/ncs_navigator/warehouse/transformers/mdes_csv/table_reader.rb
Overview
A streaming reader for a CSV containing one table's-worth of MDES data.
The CSV is converted into warehouse model instances, one record per row. The CSV MUST have a header row whose cells indicate the variable contained in each column.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(configuration, model_designator, filename) ⇒ TableReader
constructor
A new instance of TableReader.
- #name ⇒ Object
Constructor Details
#initialize(configuration, model_designator, filename) ⇒ TableReader
Returns a new instance of TableReader.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ncs_navigator/warehouse/transformers/mdes_csv/table_reader.rb', line 23 def initialize(configuration, model_designator, filename) @configuration = configuration @model = if Class === model_designator model_designator else configuration.model(model_designator.to_s) end @filename = filename end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
15 16 17 |
# File 'lib/ncs_navigator/warehouse/transformers/mdes_csv/table_reader.rb', line 15 def configuration @configuration end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
15 16 17 |
# File 'lib/ncs_navigator/warehouse/transformers/mdes_csv/table_reader.rb', line 15 def filename @filename end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
15 16 17 |
# File 'lib/ncs_navigator/warehouse/transformers/mdes_csv/table_reader.rb', line 15 def model @model end |
Instance Method Details
#each ⇒ Object
38 39 40 41 42 |
# File 'lib/ncs_navigator/warehouse/transformers/mdes_csv/table_reader.rb', line 38 def each CSV.foreach(filename, :headers => true, :header_converters => [:downcase]) do |row| yield create_instance_for_row(row) end end |
#name ⇒ Object
34 35 36 |
# File 'lib/ncs_navigator/warehouse/transformers/mdes_csv/table_reader.rb', line 34 def name "#{filename} => #{model.mdes_table_name} table" end |