sbi-security 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e69337392b0e46a91cdf5158e5c6d5742688129
4
- data.tar.gz: 3995e86bdb82046a77afebf11f04a77c6497e073
3
+ metadata.gz: 276da7a24142d8afb718cecab458f226dc0e5339
4
+ data.tar.gz: 85bd5f0ead7b83bf2f26bf5dab7275f70f6af16f
5
5
  SHA512:
6
- metadata.gz: 4f36e009baac158e8892bf15e60e0215001cd5fa7441bd2c19ea7cfd7d0de4b2e5679ee2e8dd86daba11ef11703dbe2c5e6418e0a800d79c67d42c7f7c11ca0a
7
- data.tar.gz: a4e833b76541eaa5125b5c67710e5440b6c295a59fdf77a3734b11f9921c2122606ab4b523288dbdfb1ae23882821dbc24877bab7d27d78deb6f20f66846b048
6
+ metadata.gz: 79c919bd54f9baffc7ee701b5abf2462b79a322ad195ce05e3b87b6d8b3cd31d332e61f3ae7d4f70c9f535617c0b5a0264c65cebaa83498c29adfe5258c4127e
7
+ data.tar.gz: ca8a8b2e4d0404961bb8f093f45b3cda3083a09db3f3d9a99e2e8da66da28871a6cd0896e07b3e8ad7d9a741bcfd6d7ac118acd5e21b25985d5fbbefa4c1f3d4
@@ -44,41 +44,49 @@ module Sbi::Security
44
44
  find(:xpath, "//input[@id='top_stock_sec']").set code
45
45
  find("img[title='株価検索']").click
46
46
 
47
- # SBI security has XHR for fetching information. Need to wait until page finish to emulate JavaScript.
48
- loop do
49
- if find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text != "--"
50
- break
47
+ begin
48
+ # SBI security has XHR for fetching information. Need to wait until page finish to emulate JavaScript.
49
+ loop do
50
+ if find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text != "--"
51
+ break
52
+ end
53
+ sleep 0.1
51
54
  end
52
- sleep 1
55
+ rescue Capybara::ElementNotFound
56
+ retry
53
57
  end
54
58
 
55
- price_ratio, price_ratio_percentage = all(:xpath, "//td[@id='MTB0_1']/p/span").map { |td| td.text.gsub(/,/, "") }
56
- start_price, end_price, highest_price, total_stock, lowest_price, total_price = all(:xpath, "//table[@class='tbl690']/tbody/tr/td/p/span[@class='fm01']").map { |td| td.text.gsub(/,/, "") }
59
+ begin
60
+ price_ratio, price_ratio_percentage = all(:xpath, "//td[@id='MTB0_1']/p/span").map { |td| td.text.gsub(/,/, "") }
61
+ start_price, end_price, highest_price, total_stock, lowest_price, total_price = all(:xpath, "//table[@class='tbl690']/tbody/tr/td/p/span[@class='fm01']").map { |td| td.text.gsub(/,/, "") }
57
62
 
58
- order_books = all(:xpath, "//div[@class='itaTbl02']/table/tbody/tr").drop(1).map do |tr|
59
- sell_volume, price, buy_volume = tr.all(:xpath, "./td").map(&:text)
63
+ order_books = all(:xpath, "//div[@class='itaTbl02']/table/tbody/tr").drop(1).map do |tr|
64
+ sell_volume, price, buy_volume = tr.all(:xpath, "./td").map(&:text)
60
65
 
61
- OrderBook.new(
62
- volume: sell_volume.empty? ? buy_volume : sell_volume,
63
- price: price,
64
- type: sell_volume.empty? ? "buy" : "sell"
66
+ OrderBook.new(
67
+ volume: sell_volume.empty? ? buy_volume : sell_volume,
68
+ price: price,
69
+ type: sell_volume.empty? ? "buy" : "sell"
70
+ )
71
+ end
72
+
73
+ Stock.new(
74
+ code: code,
75
+ name: find(:xpath, "//h3/span[@class='fxx01']").text,
76
+ price: find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text.gsub(/,/, ""),
77
+ price_ratio: empty_string_to_num(price_ratio).to_i,
78
+ price_ratio_percentage: empty_string_to_num(price_ratio_percentage).to_f,
79
+ start_price: start_price.to_i,
80
+ end_price: end_price,
81
+ highest_price: highest_price.to_i,
82
+ total_stock: total_stock.to_i,
83
+ lowest_price: lowest_price.to_i,
84
+ total_price: total_price.to_i * 1000,
85
+ order_books: order_books
65
86
  )
87
+ rescue Selenium::WebDriver::Error::StaleElementReferenceError
88
+ retry
66
89
  end
67
-
68
- Stock.new(
69
- code: code,
70
- name: find(:xpath, "//h3/span[@class='fxx01']").text,
71
- price: find(:xpath, "//td[@id='MTB0_0']/p/em/span[@class='fxx01']").text.gsub(/,/, ""),
72
- price_ratio: empty_string_to_num(price_ratio).to_i,
73
- price_ratio_percentage: empty_string_to_num(price_ratio_percentage).to_f,
74
- start_price: start_price.to_i,
75
- end_price: end_price,
76
- highest_price: highest_price.to_i,
77
- total_stock: total_stock.to_i,
78
- lowest_price: lowest_price.to_i,
79
- total_price: total_price.to_i * 1000,
80
- order_books: order_books
81
- )
82
90
  end
83
91
 
84
92
  private
@@ -1,5 +1,5 @@
1
1
  module Sbi
2
2
  module Security
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sbi-security
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - camelmasa