Class: Drudgery::Extractors::CSVExtractor
- Inherits:
-
Object
- Object
- Drudgery::Extractors::CSVExtractor
- Defined in:
- lib/drudgery/extractors/csv_extractor.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #col_sep ⇒ Object
- #col_sep=(char) ⇒ Object
- #extract ⇒ Object
-
#initialize(filepath, options = {}) ⇒ CSVExtractor
constructor
A new instance of CSVExtractor.
- #record_count ⇒ Object
Constructor Details
#initialize(filepath, options = {}) ⇒ CSVExtractor
Returns a new instance of CSVExtractor.
6 7 8 9 10 11 |
# File 'lib/drudgery/extractors/csv_extractor.rb', line 6 def initialize(filepath, ={}) @filepath = filepath @options = { :headers => true }.merge() @name = "csv:#{File.basename(@filepath)}" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/drudgery/extractors/csv_extractor.rb', line 4 def name @name end |
Instance Method Details
#col_sep ⇒ Object
13 14 15 |
# File 'lib/drudgery/extractors/csv_extractor.rb', line 13 def col_sep @options[:col_sep] end |
#col_sep=(char) ⇒ Object
17 18 19 |
# File 'lib/drudgery/extractors/csv_extractor.rb', line 17 def col_sep=(char) @options[:col_sep] = char end |
#extract ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/drudgery/extractors/csv_extractor.rb', line 21 def extract index = 0 CSV.foreach(@filepath, @options) do |row| yield [row.to_hash, index] index += 1 end end |
#record_count ⇒ Object
31 32 33 |
# File 'lib/drudgery/extractors/csv_extractor.rb', line 31 def record_count @record_count ||= calculate_record_count end |