lib/io_streams/tabular.rb in iostreams-1.1.0 vs lib/io_streams/tabular.rb in iostreams-1.1.1

- old
+ new

@@ -26,24 +26,24 @@ # # => "5,6,9" # # tabular.render({"third"=>"3", "first_field"=>"1" }) # # => "1,,3" class Tabular - autoload :Header, 'io_streams/tabular/header' + autoload :Header, "io_streams/tabular/header" module Parser - autoload :Array, 'io_streams/tabular/parser/array' - autoload :Base, 'io_streams/tabular/parser/base' - autoload :Csv, 'io_streams/tabular/parser/csv' - autoload :Fixed, 'io_streams/tabular/parser/fixed' - autoload :Hash, 'io_streams/tabular/parser/hash' - autoload :Json, 'io_streams/tabular/parser/json' - autoload :Psv, 'io_streams/tabular/parser/psv' + autoload :Array, "io_streams/tabular/parser/array" + autoload :Base, "io_streams/tabular/parser/base" + autoload :Csv, "io_streams/tabular/parser/csv" + autoload :Fixed, "io_streams/tabular/parser/fixed" + autoload :Hash, "io_streams/tabular/parser/hash" + autoload :Json, "io_streams/tabular/parser/json" + autoload :Psv, "io_streams/tabular/parser/psv" end module Utility - autoload :CSVRow, 'io_streams/tabular/utility/csv_row' + autoload :CSVRow, "io_streams/tabular/utility/csv_row" end attr_reader :format, :header, :parser # Parse a delimited data source. @@ -130,10 +130,11 @@ # # Example: # register_format(:csv, IOStreams::Tabular::Parser::Csv) def self.register_format(format, parser) raise(ArgumentError, "Invalid format #{format.inspect}") unless format.nil? || format.to_s =~ /\A\w+\Z/ + @formats[format.nil? ? nil : format.to_sym] = parser end # De-Register a file format # @@ -141,10 +142,11 @@ # # Example: # register_extension(:xls) def self.deregister_format(format) raise(ArgumentError, "Invalid format #{format.inspect}") unless format.to_s =~ /\A\w+\Z/ + @formats.delete(format.to_sym) end # Returns [Array<Symbol>] the list of registered formats def self.registered_formats @@ -161,10 +163,10 @@ end # Returns the parser to use with tabular for the supplied file_name def self.parser_class_for_file_name(file_name) format = nil - file_name.to_s.split('.').reverse_each do |ext| + file_name.to_s.split(".").reverse_each do |ext| if @formats.include?(ext.to_sym) format = ext.to_sym break end end