Class: Compactor::Amazon::ScrapedRow
- Defined in:
- lib/compactor/scraped_row.rb
Instance Method Summary collapse
- #can_download_report? ⇒ Boolean
- #date_range ⇒ Object
- #deposit_amount ⇒ Object
- #download_report ⇒ Object
- #download_report!(validate = false) ⇒ Object
-
#initialize(node, mechanize) ⇒ ScrapedRow
constructor
A new instance of ScrapedRow.
- #not_settled_report? ⇒ Boolean
- #reload ⇒ Object
- #report_buttons ⇒ Object
- #request_report ⇒ Object
-
#requestable_report? ⇒ Boolean
A settlement period (row) is considered ready to be parsed if it’s not processing, open or in progress.
Constructor Details
#initialize(node, mechanize) ⇒ ScrapedRow
Returns a new instance of ScrapedRow.
4 5 6 7 |
# File 'lib/compactor/scraped_row.rb', line 4 def initialize(node, mechanize) @node = node @mechanize = mechanize end |
Instance Method Details
#can_download_report? ⇒ Boolean
9 10 11 |
# File 'lib/compactor/scraped_row.rb', line 9 def can_download_report? !.blank? end |
#date_range ⇒ Object
79 80 81 |
# File 'lib/compactor/scraped_row.rb', line 79 def date_range @date_range ||= @node.search("td:first-child a").text end |
#deposit_amount ⇒ Object
74 75 76 77 |
# File 'lib/compactor/scraped_row.rb', line 74 def deposit_amount @deposit_amount = fetch_deposit_amount if !@deposit_amount @deposit_amount end |
#download_report ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/compactor/scraped_row.rb', line 28 def download_report = = () report_url = [].node["href"] report_identifier = [].node.search(".button_label").text type = ReportScraper.report_type(report_identifier) response_body = @mechanize.get(report_url).body [type, response_body] end |
#download_report!(validate = false) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/compactor/scraped_row.rb', line 19 def download_report!(validate=false) r_type, r_data = download_report # fail if Amazon is saying that total is X but the calculated total is Y validate!(r_type, r_data) if validate [r_type, r_data] end |
#not_settled_report? ⇒ Boolean
65 66 67 68 69 70 71 72 |
# File 'lib/compactor/scraped_row.rb', line 65 def not_settled_report? text = last_div.text # Is the report not settled yet? (in pending-like state) ["(Processing)", "(Open)", "In Progress"].any? do |report_state| text.include?(report_state) end end |
#reload ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/compactor/scraped_row.rb', line 39 def reload table_rows.each do |row| row = ScrapedRow.new(row, @mechanize) return row if row.date_range == date_range end nil end |
#report_buttons ⇒ Object
13 14 15 16 17 |
# File 'lib/compactor/scraped_row.rb', line 13 def last_cell.search(".secondarySmallButton").map do |ele| Mechanize::Page::Link.new(ele.parent, @mechanize, @mechanize.page) end end |
#request_report ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/compactor/scraped_row.rb', line 48 def request_report = last_cell.search(".regenerateButton")[0] = ['id'] @mechanize.post("/gp/payments-account/redrive.html", { "groupId" => }) end |
#requestable_report? ⇒ Boolean
A settlement period (row) is considered ready to be parsed if it’s not processing, open or in progress. Also the “regenerate” button is not present. This means that all is left is 1 or more buttons to get the actual reports
61 62 63 |
# File 'lib/compactor/scraped_row.rb', line 61 def requestable_report? !last_cell.search(".regenerateButton").empty? end |