vladstamatin / accounts-data-script

ruby script for scrapping web data and store it to json
0 stars 0 forks source link

Update your code #2

Closed Stepandanci closed 4 years ago

Stepandanci commented 4 years ago

You started writing a test task well.

You need to write a test for your code. Your will check methods parse_accounts and parse_transactions. Here is a list of tasks for you to update your code.

  1. Read the Ruby Style Guide https://rubystyle.guide
  2. Separate class Account and class Transactions, no need to inherit Account class to Transactions. Move class Account to file account.rb and Move class Transaction to file transaction.rb
  3. Parse all accounts and all transactions. Not only 1 account and recent transactions list.
  4. Set dates in the bank and fetch 2 months of transactions.
  5. I need the ability to leave comments under any line of code. Please, rename file Connect.rb to bendigobank.rb
  6. Separate methods for fetching and parsing data

Update code structure

class Bendigobank

  def execute
    connect
    fetch_accounts
    fetch_transactions
    show_result
  end

  def connect
    # here you log in to the bank
  end

  def fetch_accounts
    # fetch html data using nokogiri, take only fragment of html.
    html = Nokogiri::HTML.fragment(browser.div(class: "accounts-list").html)
    parse_accounts(html)
  end

  def fetch_transactions
    @accounts.each do |account|
      # go to transactions
      set_dates # set dates for 2 months

      # add transactions to account
      parse_transactions(account, html)
    end
  end

  def parse_accounts(html)
    # Iterate accounts unsing css selectors
    html.css("ol.grouped-list__group__items li").each do |li|
      # parse data here

      account = Account.new(name, balance, currency_code) # create account here 
      @accounts << account # add to accounts array
    end
  end

  def parse_transactions(account, html)
    # parse transactions here
  end
end

Good luck!

Stepandanci commented 4 years ago

Your next task to write tests. 1) Read about Rspec. It is a framework for test your code.

2) Create bendigobank_spec.rb file. In bendigobank_spec.rb file describe class bendigobank. Save 2 HTML files 'accounts.html' and 'transactions.html'.

3) Write specs for parse_accounts and parse_transactions. Show parsing results. Accounts and transactions count and a data example for 1 account and 1 transaction.

Code fragment example.

html     = # File Read 'accounts.html' with Nokogiri HTML
accounts = YourClass.parse_accounts(html)

expect(accounts.count).to eq(2)

expect(accounts[0].to_hash).to eq(
  {
    ...
  }
)

Instruction how to save the HTML file

  1. press F12
  2. find element
  3. right-click
  4. copy outerHTML
  5. save in accounts.html

accounts_html

vladstamatin commented 4 years ago

ok, i will follow these steps, also thank you for code review

Stepandanci commented 4 years ago

It looks better now. Continue to update your code.

Do not use hardcoded values, write universal code. I recommend you to read:

I recommend you to use Pry runtime developer console to handle your code. Read about Pry here https://github.com/pry/pry Run your code ruby example.rb, use method binding.pry

  def execute
    binding.pry # You stop at this line and can debug your code

    your code
  end

Write tests using Rspec.

Stepandanci commented 4 years ago

Your Task is partially completed. I will write you some tips for updating your code.

vladstamatin commented 4 years ago

Good, thank you for tips, very helpfull !

Stepandanci commented 4 years ago

It looks better. Update code and resolve the latest discussions.