lib/io_streams/tabular/parser/psv.rb in iostreams-0.15.0 vs lib/io_streams/tabular/parser/psv.rb in iostreams-0.16.0
- old
+ new
@@ -4,19 +4,23 @@
# For parsing a single line of Pipe-separated values
class Psv < Base
# Returns [Array<String>] the header row.
# Returns nil if the row is blank.
def parse_header(row)
+ return row if row.is_a?(::Array)
+
unless row.is_a?(String)
- raise(Tabular::Errors::InvalidHeader, "Format is :psv. Invalid input header: #{row.class.name}")
+ raise(IOStreams::Errors::InvalidHeader, "Format is :psv. Invalid input header: #{row.class.name}")
end
row.split('|')
end
# Returns [Array] the parsed PSV line
def parse(row)
- raise(Tabular::Errors::TypeMismatch, "Format is :psv. Invalid input: #{row.class.name}") unless row.is_a?(String)
+ return row if row.is_a?(::Array)
+
+ raise(IOStreams::Errors::TypeMismatch, "Format is :psv. Invalid input: #{row.class.name}") unless row.is_a?(String)
row.split('|')
end
# Return the supplied array as a single line JSON string.