module ReciteCSV::Reader::Core
Attributes
csv_options[R]
file[R]
file_options[R]
Public Class Methods
new(file, file_options: {}, **options)
click to toggle source
# File lib/recite_csv/reader/core.rb, line 12 def initialize(file, file_options: {}, **options) @file = file @file_options = file_options @csv_options = options.merge(self.class::DEFAULT_CSV_OPTIONS) end
Public Instance Methods
each(&block)
click to toggle source
# File lib/recite_csv/reader/core.rb, line 18 def each(&block) if block_given? _each(&block) else self.to_enum end end
Private Instance Methods
_each(&block)
click to toggle source
# File lib/recite_csv/reader/core.rb, line 28 def _each(&block) f = _open begin _foreach(f, &block) ensure f.close if self.file.is_a?(::String) end end
_foreach(file) { |classrow| ... }
click to toggle source
# File lib/recite_csv/reader/core.rb, line 50 def _foreach(file) ::CSV.new(file, **self.csv_options).each do |raw_row| yield self.class::Row.new(raw_row) end self end
_open()
click to toggle source
# File lib/recite_csv/reader/core.rb, line 37 def _open return self.file unless self.file.is_a?(::String) args = Array(self.file_options) if args.last.is_a?(::Hash) args = args.dup kw_args = args.pop ::File.open(self.file, *args, **kw_args) else ::File.open(self.file, *args) end end