lib/io_streams/tabular/header.rb in iostreams-0.20.3 vs lib/io_streams/tabular/header.rb in iostreams-1.0.0.beta

- old
+ new

@@ -88,11 +88,14 @@ def to_hash(row, cleanse = true) return if IOStreams::Utils.blank?(row) case row when Array - raise(IOStreams::Errors::InvalidHeader, "Missing mandatory header when trying to convert a row into a hash") unless columns + unless columns + raise(IOStreams::Errors::InvalidHeader, 'Missing mandatory header when trying to convert a row into a hash') + end + array_to_hash(row) when Hash cleanse && columns ? cleanse_hash(row) : row else raise(IOStreams::Errors::TypeMismatch, "Don't know how to convert #{row.class.name} to a Hash") @@ -102,11 +105,15 @@ def to_array(row, cleanse = true) if row.is_a?(Hash) && columns row = cleanse_hash(row) if cleanse row = columns.collect { |column| row[column] } end - raise(IOStreams::Errors::TypeMismatch, "Don't know how to convert #{row.class.name} to an Array without the header columns being set.") unless row.is_a?(Array) + + unless row.is_a?(Array) + raise(IOStreams::Errors::TypeMismatch, "Don't know how to convert #{row.class.name} to an Array without the header columns being set.") + end + row end private @@ -138,9 +145,8 @@ cleansed.gsub!(/\s+/, '_') cleansed.gsub!(/-+/, '_') cleansed.gsub!(/\W+/, '') cleansed end - end end end