Class: Scruber::Helpers::DictionaryReader::Csv
- Defined in:
- lib/scruber/helpers/dictionary_reader/csv.rb
Instance Method Summary collapse
-
#initialize(file_path) ⇒ Csv
constructor
A new instance of Csv.
- #read(options = {}) ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Csv
Returns a new instance of Csv.
5 6 7 |
# File 'lib/scruber/helpers/dictionary_reader/csv.rb', line 5 def initialize(file_path) @file_path = file_path end |
Instance Method Details
#read(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/scruber/helpers/dictionary_reader/csv.rb', line 9 def read(={}) col_sep = .delete(:col_sep) || ',' CSV.foreach(@file_path, col_sep: col_sep, headers: true, encoding: 'utf-8') do |csv_row| if .blank? yield csv_row else if .all?{|(k,v)| csv_row[k.to_s] == v } yield csv_row end end end end |