Class: SimpleCsvReader::Reader
- Inherits:
-
Object
- Object
- SimpleCsvReader::Reader
- Defined in:
- lib/simple_csv_reader/reader.rb
Class Method Summary collapse
- .default_converters ⇒ Object
- .default_converters=(converters) ⇒ Object
- .default_nil_value ⇒ Object
- .default_nil_value=(value) ⇒ Object
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(path, headers, **options) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(path, headers, **options) ⇒ Reader
Returns a new instance of Reader.
8 9 10 11 12 |
# File 'lib/simple_csv_reader/reader.rb', line 8 def initialize(path, headers, **) @path = path @headers = headers @options = end |
Class Method Details
.default_converters ⇒ Object
27 28 29 |
# File 'lib/simple_csv_reader/reader.rb', line 27 def self.default_converters instance_variable_defined?(:@default_converters) ? @default_converters : :numeric end |
.default_converters=(converters) ⇒ Object
31 32 33 |
# File 'lib/simple_csv_reader/reader.rb', line 31 def self.default_converters=(converters) @default_converters = converters end |
.default_nil_value ⇒ Object
35 36 37 |
# File 'lib/simple_csv_reader/reader.rb', line 35 def self.default_nil_value instance_variable_defined?(:@default_nil_value) ? @default_nil_value : nil end |
.default_nil_value=(value) ⇒ Object
39 40 41 |
# File 'lib/simple_csv_reader/reader.rb', line 39 def self.default_nil_value=(value) @default_nil_value = value end |
Instance Method Details
#each(&block) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple_csv_reader/reader.rb', line 14 def each(&block) return enum_for(:each) unless block_given? # NOTE: The first line is a header csv.each.with_index(2) do |row, row_number| hash = row.to_h next if hash.compact.empty? # NOTE: blank row filtered_hash = @options[:include_unspecified_headers] ? hash : hash.slice(*@headers.keys) yield(filtered_hash, row_number: row_number) end end |