class BcaParser::Parser

Attributes

account_number[RW]
end_date[RW]
end_month[RW]
month[RW]
start_date[RW]
start_month[RW]
success[R]
transaction_check_type[RW]

Public Class Methods

new(username, password, file_to_open='') click to toggle source
# File lib/bcaparser/parser.rb, line 13
def initialize(username, password, file_to_open='')
  @username = String(username)
  @password = String(password)
  @browser = Watir::Browser.start "https://ibank.klikbca.com"
  @browser.window.resize_to(100, 90)
end

Public Instance Methods

check_balance() click to toggle source
# File lib/bcaparser/parser.rb, line 116
def check_balance
  enter_informasi_saldo
  page_html = get_html_nokogiri(@atm.html)
  @account.balance[:account_number] = page_html.xpath("/html/body/table[3]/tbody/tr[2]/td[1]/div/font").inner_text
  @account.balance[:total] = page_html.xpath("/html/body/table[3]/tbody/tr[2]/td[4]/div/font").inner_text
  @account.print_balance
end
check_daily_transaction(start_date, start_month, end_date, end_month) click to toggle source
# File lib/bcaparser/parser.rb, line 124
def check_daily_transaction(start_date, start_month, end_date, end_month)
  enter_mutasi_rekening
  @atm.select_list(:id, "startDt").select("#{start_date}")
  @atm.select_list(:id, "startMt").select("#{TimeKeeper.getIndonesianMonth(start_month)}")
  @atm.select_list(:id, "endDt").select("#{end_date}")
  @atm.select_list(:id, "endMt").select("#{TimeKeeper.getIndonesianMonth(end_month)}")
  @atm.button(:value,"Lihat Mutasi Rekening").click
  page_html = get_html_nokogiri(@atm.html)
  get_transaction_list_table(page_html)
end
check_monthly_transaction(month) click to toggle source
# File lib/bcaparser/parser.rb, line 135
def check_monthly_transaction(month)
  enter_mutasi_rekening
  @atm.radio(:value, "2").set
  @atm.select_list(:id, "x").select("#{TimeKeeper.getIndonesianMonth(month)}")
  @atm.button(:value,"Lihat Mutasi Rekening").click
  page_html = get_html_nokogiri(@atm.html)
  get_transaction_list_table(page_html)
end
close() click to toggle source
# File lib/bcaparser/parser.rb, line 151
def close
  puts "Closing the browser"
  @browser.close
end
date_correct?(start_date, start_month, end_date, end_month) click to toggle source
# File lib/bcaparser/parser.rb, line 71
def date_correct?(start_date, start_month, end_date, end_month)
  start_day = TimeKeeper.makeDateFromString(start_date, start_month, Time.new.year)
  end_day = TimeKeeper.makeDateFromString(end_date, end_month, Time.new.year)
  TimeKeeper.compareDate(start_day, end_day)
end
displayDataInScreen() click to toggle source
# File lib/bcaparser/parser.rb, line 156
def displayDataInScreen
  @account.print_transactions
end
enter_informasi_rekening() click to toggle source
# File lib/bcaparser/parser.rb, line 53
def enter_informasi_rekening
  @browser.frame(:name, "menu").link(:text, "Informasi Rekening").click
end
enter_informasi_saldo() click to toggle source
# File lib/bcaparser/parser.rb, line 57
def enter_informasi_saldo
  enter_informasi_rekening
  @browser.frame(:name, "menu").link(:text, "Informasi Saldo").click
end
enter_mutasi_rekening() click to toggle source
# File lib/bcaparser/parser.rb, line 62
def enter_mutasi_rekening
  enter_informasi_rekening
  @browser.frame(:name, "menu").link(:text, "Mutasi Rekening").click
end
get_html_nokogiri(page_to_parse_html) click to toggle source
# File lib/bcaparser/parser.rb, line 67
def get_html_nokogiri(page_to_parse_html)
  Nokogiri::HTML.parse(page_to_parse_html)
end
get_transaction_list_table(page_html) click to toggle source
# File lib/bcaparser/parser.rb, line 85
def get_transaction_list_table(page_html)
  if page_html.at_xpath('/html/body/table[3]/tbody/tr[3]/td/table/tbody/tr[5]/td[1]')
    @success = true
    acc = 1
    table_row = page_html.at_xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]")
    while table_row != nil
      transactionInfo = []
      transaction = {}
      if acc == 1
        transactionInfo << page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[1]/div/font/b").inner_text
        transactionInfo << page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[2]/div/font/b").inner_text
        transactionInfo << page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[3]/div/font/b").inner_text
        transactionInfo << page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[4]/div/font/b").inner_text
        transactionInfo << page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[5]/div/font/b").inner_text
      else
        transaction[:date] = page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[1]/div/font").inner_text
        transaction[:info] = page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[2]/div/font").inner_text
        transaction[:amount] = page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[4]/div/font").inner_text
        transaction[:type] = page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[5]/div/font").inner_text
        transaction[:balance] = page_html.xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]/td[6]/div/font").inner_text
      end
      @account.add_transaction(transaction)
      acc += 1
      table_row = page_html.at_xpath("/html/body/table[3]/tbody/tr[2]/td/table/tbody/tr[#{acc}]")
    end
  else
    @success = false
  end
end
info() click to toggle source
# File lib/bcaparser/parser.rb, line 144
def info
  puts "\nGetting data..."
  puts "Watir is automating the browser..."
  puts "Nokogiri is parsing..."
end
logged?() click to toggle source
# File lib/bcaparser/parser.rb, line 49
def logged?
  @logged_in
end
login() click to toggle source
# File lib/bcaparser/parser.rb, line 20
def login
  info
  @browser.text_field(:id, "user_id").set(@username)
  @browser.text_field(:id, "pswd").set(@password)
  @browser.button(:value,"LOGIN").click
  @browser.button(:value,"LOGIN").click
  @logged_in = @browser.browser.frame(:name, "atm") != nil
  if logged?
    @atm = @browser.frame(:name, "atm")
    @header = @browser.frame(:name, "header")
    page_html = get_html_nokogiri(@atm.html)
    text = page_html.xpath("/html/body/table[4]/tbody/tr[3]/td/center/b/font").inner_text.split(',')
    name = text[0]
    @account = Account.new(name)
  end
end
logout() click to toggle source
# File lib/bcaparser/parser.rb, line 41
def logout
  if logged?
    @header.link(:text, "[ LOGOUT ]").click
    puts "\nLogout Success"
    @logged_in = false
  end
end
saveDataToCSV(filename) click to toggle source
# File lib/bcaparser/parser.rb, line 161
def saveDataToCSV(filename)
  CSV.open(File.join(Dir.pwd, "#{filename}.csv"), "w") do |csv|
    csv << ["Tanggal", "Informasi", "Jumlah", "Jenis Mutasi", "Saldo"]
    @account.transactions.each do |transaction|
      next if transaction[:date].nil?
      csv << [transaction[:date], transaction[:info], transaction[:amount], transaction[:type], transaction[:balance]]
    end
  end
  puts "#{filename}.csv has been saved to #{Dir.pwd}"
end
saveDataToSpreadsheet(filename) click to toggle source
# File lib/bcaparser/parser.rb, line 172
def saveDataToSpreadsheet(filename)
  book = Spreadsheet::Workbook.new
  sheet1 = book.create_worksheet
  sheet1.row(0).replace ["Tanggal", "Informasi", "Jumlah", "Tipe", "Saldo"]
  count = 1
  @account.transactions.each do |transaction|
    next if transaction[:date].nil?
    sheet1.row(count).replace [transaction[:date], transaction[:info], transaction[:amount], transaction[:type], transaction[:balance]]
    count += 1
  end
  book.write(File.join(Dir.pwd, "#{filename}.xls"))
  puts "#{filename}.xls has been saved to #{Dir.pwd}"
end
save_balance_to_sql() click to toggle source
# File lib/bcaparser/parser.rb, line 77
def save_balance_to_sql
  balance = check_balance
  puts @account.name


end
transaction_success?() click to toggle source
# File lib/bcaparser/parser.rb, line 37
def transaction_success?
  @success
end