Class: ParseUtil::HandleSwissmedicErrors
- Inherits:
-
Object
- Object
- ParseUtil::HandleSwissmedicErrors
- Defined in:
- lib/oddb2xml/parslet_compositions.rb
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
35 36 37 38 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 35 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.
24 25 26 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 24 def nrParsingErrors @nrParsingErrors end |
Instance Method Details
#apply_fixes(string) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 49 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 } @nrLines += 1 result end |
#report ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 40 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
28 29 30 31 32 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 28 def reset_errors @errors = [] @nrLines = 0 @nrParsingErrors = 0 end |