Class: ParseUtil::HandleSwissmedicErrors
- Inherits:
-
Object
- Object
- ParseUtil::HandleSwissmedicErrors
- Defined in:
- lib/oddb2xml/parslet_compositions.rb
Overview
this class is responsible to patch errors in swissmedic entries after oddb.org detected them, as it takes sometimes a few days (or more) till they get corrected Reports the number of occurrences of each entry
Defined Under Namespace
Classes: ErrorEntry
Instance Attribute Summary collapse
-
#nrParsingErrors ⇒ Object
Returns the value of attribute nrParsingErrors.
Instance Method Summary collapse
- #apply_fixes(string) ⇒ Object
-
#initialize(error_entries) ⇒ HandleSwissmedicErrors
constructor
error_entries should be a hash of pattern, replacement.
- #report ⇒ Object
- #reset_errors ⇒ Object
Constructor Details
#initialize(error_entries) ⇒ HandleSwissmedicErrors
error_entries should be a hash of pattern, replacement
32 33 34 35 |
# 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 |
Instance Attribute Details
#nrParsingErrors ⇒ Object
Returns the value of attribute nrParsingErrors.
21 22 23 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 21 def nrParsingErrors @nrParsingErrors end |
Instance Method Details
#apply_fixes(string) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 46 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}" unless defined?(RSpec) end } @nrLines += 1 result end |
#report ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 37 def report s = ["Report of changed compositions in #{@nrLines} lines. Had #{@nrParsingErrors} parsing errors" ] @errors.each { |entry| s << " replaced #{entry.nr_occurrences} times '#{entry.pattern}' by '#{entry.replacement}'" } s end |
#reset_errors ⇒ Object
25 26 27 28 29 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 25 def reset_errors @errors = [] @nrLines = 0 @nrParsingErrors = 0 end |