thaistock 0.0.0 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/thaistock.rb +69 -61
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 024470e4192d3b2cdf379fbb423ba8498515da8c236d87062c0bba69f0631b97
4
- data.tar.gz: 758cb2bb2c253c990cb8ed5c26c3c3fb8228cd9cac7869de7db4f68eaba3ce68
3
+ metadata.gz: cb4488b0a4e82b04eee939eeb8b5364b466216638f559841494180ea7b4e68e8
4
+ data.tar.gz: 9cbb7f8ecd81f0127a58e82f169277df67ca2d709591f50b0aa6144b817655d6
5
5
  SHA512:
6
- metadata.gz: '062695d95eb60435f216b5d0ec92badc1451fb45d55bc91aadd60a036e1779652a80866bd1ac3ae6dab61ff2d3fbea26c7f7c445c231f9cdc59095b4278c0262'
7
- data.tar.gz: df0af877159645a5ceb8e86a835c57616cf1a633a46ac1e2dac845c3f20fe0ff67b652534de86a50e2c848de17147d3d6e76811726c04e0f7351f69837051db2
6
+ metadata.gz: 38daabec7318b6e42eefba3fe29f630ac4389617dcb45d48be80ab0ab1b8f618b254aa8454a6f14672b97cd982d1e13dc29b7c14a86edbb74488447dce6b1e84
7
+ data.tar.gz: 83d5b817b1754486a8274684e5c7c8729c87ca1533b26a13135192811555ac87c557e64970984eebbc1fdb3b5753beabda6c6f28c62663c4fc16528f497419e2
data/lib/thaistock.rb CHANGED
@@ -5,82 +5,90 @@
5
5
  require 'open-uri'
6
6
  require 'nokogiri'
7
7
 
8
-
9
- # generate openable URL for Nokogiri
10
- #
11
- # @param [String] URL's postfix
12
- # @return [String] openable URL
13
- def get_link(url)
14
- prefix = "https://www.set.or.th"
15
- return prefix + url.values[0]
16
- end
8
+ class ThaiStock
9
+
10
+ # generate openable URL for Nokogiri
11
+ #
12
+ # @param [String] URL's postfix
13
+ # @return [String] openable URL
14
+ def self.get_link(url)
15
+ prefix = "https://www.set.or.th"
16
+ return prefix + url.values[0]
17
+ end
17
18
 
18
19
 
19
- # open url with Nokogiri
20
- #
21
- # @param [String] URL
22
- # @return [Nokogiri] object
23
- def open_link(url)
24
- return Nokogiri::HTML(URI.open("#{url}"))
25
- end
20
+ # open url with Nokogiri
21
+ #
22
+ # @param [String] URL
23
+ # @return [Nokogiri] object
24
+ def self.open_link(url)
25
+ return Nokogiri::HTML(URI.open("#{url}"))
26
+ end
26
27
 
27
28
 
28
- # check index of asset column
29
- #
30
- # @param [Nokogiri] object
31
- # @return [Int] column of asset
32
- def check_asset_index(stock)
33
- index = 1
34
- begin
35
- while true
36
- stock_detail = stock.css("th[#{index}]").first.text
37
- if stock_detail.to_s.include? "ไตรมาส"
38
- break
39
- else
40
- index += 1
29
+ # check index of asset column
30
+ #
31
+ # @param [Nokogiri] object
32
+ # @return [Int] column of asset
33
+ def self.check_asset_index(stock)
34
+ index = 1
35
+ begin
36
+ while true
37
+ stock_detail = stock.css("th[#{index}]").first.text
38
+ if stock_detail.to_s.include? "ไตรมาส"
39
+ break
40
+ else
41
+ index += 1
42
+ end
41
43
  end
44
+ rescue NoMethodError
45
+ index = 10
42
46
  end
43
- rescue NoMethodError
44
- index = 10
47
+ return index
45
48
  end
46
- return index
47
- end
48
49
 
49
50
 
50
- url = "https://www.set.or.th/set/commonslookup.do"
51
- source = open_link(url)
51
+ # Excucute the program
52
+ def self.thai_stock
52
53
 
53
- source.search("a").map{ |prefix_href|
54
- if prefix_href.to_s.include? "prefix="
54
+ url = "https://www.set.or.th/set/commonslookup.do"
55
+ source = self.open_link(url)
55
56
 
56
- # open each catagories
57
- prefix_menu = open_link(get_link(prefix_href))
58
- prefix_menu.search("td a").map{ |stock|
57
+ source.search("a").map{ |prefix_href|
58
+ if prefix_href.to_s.include? "prefix="
59
59
 
60
- # open each stock in the following catagories
61
- stock_info = open_link(get_link(stock))
60
+ # open each catagories
61
+ prefix_menu = self.open_link(get_link(prefix_href))
62
+ prefix_menu.search("td a").map{ |stock|
62
63
 
63
- # print company's name
64
- company_name = stock_info.css("h3").text
65
- print company_name
66
- print " : "
64
+ # open each stock in the following catagories
65
+ stock_info = self.open_link(get_link(stock))
67
66
 
68
- stock_info.search("a").map{ |stock_asset|
69
- if stock_asset.to_s.include? "companyhighlight"
67
+ # print company's name
68
+ company_name = stock_info.css("h3").text
69
+ print company_name
70
+ print " : "
70
71
 
71
- # open each stock detail
72
- current_stock_asset = open_link(get_link(stock_asset))
73
- index = check_asset_index(current_stock_asset)
72
+ stock_info.search("a").map{ |stock_asset|
73
+ if stock_asset.to_s.include? "companyhighlight"
74
74
 
75
- begin
76
- # print company asset
77
- company_asset = current_stock_asset.css("td[#{index}]").first.text
78
- puts company_asset
79
- rescue NoMethodError
80
- puts "NO DATA FOUND"
81
- end
82
- end
83
- }
75
+ # open each stock detail
76
+ current_stock_asset = self.open_link(get_link(stock_asset))
77
+ index = self.check_asset_index(current_stock_asset)
78
+
79
+ begin
80
+ # print company asset
81
+ company_asset = current_stock_asset.css("td[#{index}]").first.text
82
+ puts company_asset
83
+ rescue NoMethodError
84
+ puts "NO DATA FOUND"
85
+ end
86
+ end
87
+ }
88
+ }
89
+ end
84
90
  }
85
91
  end
86
- }
92
+ end
93
+
94
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thaistock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saruj Sattayanurak