lib/docparser/parser.rb in docparser-0.2.3 vs lib/docparser/parser.rb in docparser-0.3.0
- old
+ new
@@ -1,11 +1,12 @@
+# frozen_string_literal: true
+
require 'rubygems'
require 'bundler/setup'
require 'parallel'
+require 'logger'
require 'set'
-require 'log4r'
-require 'log4r/formatter/patternformatter'
require 'docparser/version'
require 'docparser/output'
require 'docparser/document'
require 'docparser/output/csv_output.rb'
require 'docparser/output/html_output.rb'
@@ -13,17 +14,10 @@
require 'docparser/output/yaml_output.rb'
require 'docparser/output/json_output.rb'
require 'docparser/output/multi_output.rb'
require 'docparser/output/nil_output.rb'
-Log4r.define_levels(*Log4r::Log4rConfig::LogLevels)
-logger = Log4r::Logger.new('docparser')
-output = Log4r::StdoutOutputter.new('docparser')
-output.formatter = Log4r::PatternFormatter.new(pattern: '[%l %C] %d :: %m')
-logger.outputters = output
-logger.level = Log4r::INFO
-
# The DocParser namespace
# See README.md for information on using DocParser
module DocParser
# The main parser class. This is the class you'll use to create your parser
# The real work happens in the Document class
@@ -46,15 +40,15 @@
num_processes: Parallel.processor_count + 1)
@num_processes = parallel ? num_processes : 1
@files = range ? files[range] : files
@encoding = encoding
- Log4r::Logger['docparser'].level = quiet ? Log4r::ERROR : Log4r::INFO
+ @logger = Logger.new(STDERR)
+ @logger.level = quiet ? Logger::ERROR : Logger::INFO
initialize_outputs output
- @logger = Log4r::Logger.new('docparser::parser')
@logger.info "DocParser v#{VERSION} loaded"
end
# Parses the `files`
#
@@ -86,11 +80,11 @@
if output.is_a? Output
@outputs << output
elsif output.is_a?(Array) && output.all? { |o| o.is_a? Output }
@outputs = output
elsif output
- fail ArgumentError, 'Invalid outputs specified'
+ raise ArgumentError, 'Invalid outputs specified'
end
@resultsets = Array.new(@outputs.length) { Set.new }
end
@@ -100,12 +94,14 @@
Parallel.map(@files, option => @num_processes) do |file|
# :nocov: #
parse_doc(file, &block)
# :nocov: #
end.each do |result|
+ next unless @outputs
+
result.each_with_index do |set, index|
@resultsets[index].merge(set)
- end if @outputs
+ end
end
end
def serial_process(&block)
@files.each do |file|