Class: Sbi::Security::Crawler
- Inherits:
-
Object
- Object
- Sbi::Security::Crawler
- Includes:
- Capybara::DSL
- Defined in:
- lib/sbi/security/crawler.rb
Constant Summary collapse
- TOP_PAGE =
"https://www.sbisec.co.jp/ETGate"
Instance Method Summary collapse
-
#initialize(user_id, password) ⇒ Crawler
constructor
A new instance of Crawler.
- #portfolio ⇒ Object
Constructor Details
#initialize(user_id, password) ⇒ Crawler
Returns a new instance of Crawler.
15 16 17 |
# File 'lib/sbi/security/crawler.rb', line 15 def initialize(user_id, password) login(user_id, password) end |
Instance Method Details
#portfolio ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sbi/security/crawler.rb', line 19 def portfolio find("img[title='ポートフォリオ']").click stocks = page.all(:xpath, '//table[@width="100%"]/tbody/tr[@align="center"]').each_with_index.map do |tr, i| # Ignore title row next if i == 0 _, code_and_name, _, count, value, price, price_ratio, price_ratio_percentage, profit, profit_percentage, total_value = tr.all("td").map(&:text) Stock.new( code: code_and_name.split(" ").first, name: code_and_name.split(" ").last, count: count.gsub(/,/, ""), value: value.gsub(/,/, ""), price: price.gsub(/,/, ""), price_ratio: (price_ratio == "--" ? nil : price_ratio.gsub(/,/, "").to_i), price_ratio_percentage: (price_ratio_percentage == "--" ? nil : price_ratio_percentage.gsub(/,/, "").to_f), profit: profit.gsub(/,/, ""), profit_percentage: profit_percentage.gsub(/,/, ""), total_value: total_value.gsub(/,/, "") ) end.compact Portfolio.new(stocks) end |