lib/sxp.rb in sxp-0.0.5 vs lib/sxp.rb in sxp-0.0.6

- old
+ new

@@ -24,59 +24,57 @@ autoload :List, 'sxp/list' autoload :Generator, 'sxp/generator' autoload :Reader, 'sxp/reader' ## - # Reads all S-expressions from a given input URI using the HTTP or FTP + # Reads all S-expressions from a given input URL using the HTTP or FTP # protocols. # # @param [String, #to_s] url # @param [Hash{Symbol => Object}] options # @return [Enumerable<Object>] def self.read_url(url, options = {}) - require 'open-uri' - open(url.to_s, 'rb', nil, options) { |io| read_all(io, options) } + Reader::Scheme.read_url(url, options) end ## # Reads all S-expressions from the given input files. # # @param [Enumerable<String>] filenames # @param [Hash{Symbol => Object}] options # @return [Enumerable<Object>] def self.read_files(*filenames) - options = filenames.last.is_a?(Hash) ? filenames.pop : {} - filenames.map { |filename| read_file(filename, options) }.inject { |sxps, sxp| sxps + sxp } + Reader::Scheme.read_files(*filenames) end ## # Reads all S-expressions from a given input file. # # @param [String, #to_s] filename # @param [Hash{Symbol => Object}] options # @return [Enumerable<Object>] def self.read_file(filename, options = {}) - File.open(filename.to_s, 'rb') { |io| read_all(io, options) } + Reader::Scheme.read_file(filename, options) end ## # Reads all S-expressions from the given input stream. # # @param [IO, StringIO, String] input # @param [Hash{Symbol => Object}] options # @return [Enumerable<Object>] def self.read_all(input, options = {}) - Reader::Scheme.new(input, options).read_all + Reader::Scheme.read_all(input, options) end ## # Reads one S-expression from the given input stream. # # @param [IO, StringIO, String] input # @param [Hash{Symbol => Object}] options # @return [Object] def self.read(input, options = {}) - Reader::Scheme.new(input, options).read + Reader::Scheme.read(input, options) end class << self alias_method :parse, :read alias_method :parse_all, :read_all