Created
December 4, 2015 02:10
-
-
Save moskyb/77bbcf27a6c2d17d6f16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def needs_washup?(mech, invoice_rel) | |
# Gets some info from the page at billing.flickelectric.co.nz/#{invoice_rel}, | |
# checks if the accuracy_status of the invoice is actual, and if the total due | |
# equals 0. If accuracy_status is actual and total due != 0, return true, else false | |
page = mech.get("https://uat-billing.flickelectric.co.nz/" + invoice_rel) | |
accuracy_status = page.search('dl[id="invoice_details"]').to_s.include?("actual") | |
invoice_lines = page.search('tfoot[class~="invoice-totals"]').children | |
# Strip out all of the whitespace | |
totals = invoice_lines.text.gsub(/\s+/, "") | |
# Iterate backwards through until we get a $ character - this index will be | |
# where to slice to get just the total due | |
dollar = -1 | |
while totals[dollar] != '$' | |
dollar -= 1 | |
end | |
wash_up = (totals [dollar + 1..-1].to_f != 0.00) && accuracy_status | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment