class ParseUtil::HandleSwissmedicErrors
Attributes
nrParsingErrors[RW]
Public Class Methods
new(error_entries)
click to toggle source
error_entries should be a hash of pattern, replacement
# File lib/oddb2xml/parslet_compositions.rb, line 32 def initialize(error_entries) reset_errors error_entries.each { |pattern, replacement| @errors << ErrorEntry.new(pattern, replacement, 0) } end
Public Instance Methods
apply_fixes(string)
click to toggle source
# File lib/oddb2xml/parslet_compositions.rb, line 45 def apply_fixes(string) result = string.clone @errors.each { |entry| intermediate = result.clone result = result.gsub(entry.pattern, entry.replacement) unless result.eql?(intermediate) entry.nr_occurrences += 1 puts "#{File.basename(__FILE__)}:#{__LINE__}: fixed \nbefore: #{intermediate}\nafter: #{result}" if $VERBOSE end } @nr_lines += 1 result end
report()
click to toggle source
# File lib/oddb2xml/parslet_compositions.rb, line 37 def report s = ["Report of changed compositions in #{@nr_lines} lines. Had #{@nr_parsing_errors} parsing errors"] @errors.each { |entry| s << " replaced #{entry.nr_occurrences} times '#{entry.pattern}' by '#{entry.replacement}'" } s end
reset_errors()
click to toggle source
# File lib/oddb2xml/parslet_compositions.rb, line 25 def reset_errors @errors = [] @nr_lines = 0 @nr_parsing_errors = 0 end