Skip to content

Commit

Permalink
Describe in detail what this method does. Rename method to match
Browse files Browse the repository at this point in the history
  • Loading branch information
auxesis committed Dec 18, 2016
1 parent 8bf7075 commit c44f740
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions scraper.rb
Expand Up @@ -237,8 +237,21 @@ def finalise_record!
@record = nil
end

# Fix values being spread across multiple records incorrectly
def fix_spread_values!
# Normalise the "Imposed Penalties" field across all records.
#
# There is an edge case where the dollar value normally expected on a
# "Total (x) Charges" termination line is on the next line. Because we
# use that line as the record terminator, the dollar value is pushed into the
# next record.
#
# This method:
#
# - Removes the dollar value from the "Total (x) Charges" line, because it's
# just a total that the user can automatically compute.
# - Deletes the "Total (x) Charges" dollar value that sometimes gets put into
# the next record.
#
def clean_imposed_penalties!
@records.each_with_index do |record, index|
offset = record['imposed_penalties'].size - record['offence_proven'].size
case offset
Expand Down Expand Up @@ -291,7 +304,7 @@ def extract_records_from_pages(pages)
build_records(raw_lines, columns)
end

fix_spread_values!
clean_imposed_penalties!

@records
end
Expand Down

0 comments on commit c44f740

Please sign in to comment.