API.md in row_boat-0.1.0 vs API.md in row_boat-0.2.0

- old
+ new

@@ -153,17 +153,17 @@ ## `column_mapping` ### Description -It is required that you override this method with a hash that maps columns in your CSV to their preferred names. +It is required that you override this method with either a hash that maps columns in your CSV to their preferred names or an array of your preferred column names. -By default +By default when using a hash - CSV column names are downcased symbols of what they look like in the CSV. - CSV columns that are not mapped are ignored when processing the CSV. -If you're familiar with [SmarterCSV](https://github.com/tilo/smarter_csv#documentation), this method essentially defines your `:key_mapping` and with the `:remove_unmapped_keys` setting set to `true`. +If you're familiar with [SmarterCSV](https://github.com/tilo/smarter_csv#documentation), this method essentially defines your `:key_mapping` with the `:remove_unmapped_keys` setting set to `true` when provided with a hash. When given an array it is the `:user_provided_headers` option. You can change these defaults by overriding the [`options`](#options) method. ### Example @@ -175,28 +175,39 @@ prdct_nm: :name, "price/cost_amnt": :price_in_cents } end end + +# or... + +class ImportProduct < RowBoat::Base + # other required configuration omitted for brevity + def column_mapping + [:name, :price_in_cents] + end +end ``` ## `preprocess_row` ### Description Implement this method if you need to do some work on the row before the record is inserted/updated. If you return `nil` from this method, the row will be skipped in the import. +You also have access to `row_number` here. + If the work you intend to do with the row only requires changing one attribute, it is recommended that you override [`value_converters`](#value_converters) instead of this. ### Example ```ruby class ImportProduct < RowBoat::Base # required configuration omitted for brevity def preprocess_row(row) - { default: :value }.merge(row) + { position: row_number }.merge(row) end # or... def preprocess_row(row) if row[:name] && row[:price] row