lib/docparser/parser.rb in docparser-0.2.0 vs lib/docparser/parser.rb in docparser-0.2.2
- old
+ new
@@ -30,11 +30,12 @@
# @see Document
class Parser
# @!visibility private
attr_reader :outputs, :files, :num_processes, :encoding
- # Creates a new parser instance
+ # Creates a new Parser instance
+ #
# @param files [Array] An array containing URLs or paths to files
# @param quiet [Boolean] Be quiet
# @param encoding [String] The encoding to use for opening the files
# @param parallel [Boolean] Use parallel processing
# @param output [Output, Array] The output(s), defaults to a Screenoutput
@@ -53,13 +54,16 @@
@logger = Log4r::Logger.new('docparser::parser')
@logger.info "DocParser v#{VERSION} loaded"
end
- #
# Parses the `files`
#
+ # Accepts a block which is executed for each document in the Document
+ # context where you can access the content using Nokogiri.
+ #
+ # @see Document
def parse!(&block)
@logger.info "Parsing #{@files.length} files (encoding: #{@encoding})."
start_time = Time.now
if @num_processes > 1
@@ -70,21 +74,21 @@
@logger.info 'Processing finished'
write_to_outputs
- @logger.info sprintf('Done processing in %.2fs.', Time.now - start_time)
+ @logger.info format('Done processing in %.2fs.', Time.now - start_time)
end
private
def initialize_outputs(output)
@outputs = []
if output.is_a? Output
@outputs << output
elsif output.is_a?(Array) && output.all? { |o| o.is_a? Output }
@outputs = output
- elsif !output.nil?
+ elsif output
fail ArgumentError, 'Invalid outputs specified'
end
@resultsets = Array.new(@outputs.length) { Set.new }
end