Class: FlexibleCsv::Parser
- Inherits:
-
Object
- Object
- FlexibleCsv::Parser
- Defined in:
- lib/flexible_csv.rb
Overview
Wrapper class around the FasterCSV object
Instance Method Summary collapse
-
#initialize(data, csv_parent) ⇒ Parser
constructor
A new instance of Parser.
-
#method_missing(method_name, *args, &block) ⇒ Object
proxy other methods to the @table object.
Constructor Details
#initialize(data, csv_parent) ⇒ Parser
Returns a new instance of Parser.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/flexible_csv.rb', line 56 def initialize(data, csv_parent) column_headers = [] fcsv = FasterCSV.new(data.is_a?(String) ? data : data.read, :headers => true) # reformat headers to remove punctuation, capitalization and white space # Change header labels to the key used in the column config fcsv.header_convert do |field| f = csv_parent.clean_up(field) csv_parent.column_hash.each_pair do |k,v| f = k.to_s and break if v.include?(f) end f end @table = fcsv.read end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
proxy other methods to the @table object
75 76 77 |
# File 'lib/flexible_csv.rb', line 75 def method_missing(method_name, *args, &block) @table.send(method_name, *args, &block) end |