histock-simplefilter 0.4.1 → 0.5.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f17d60747c236f7faf31b6dad84c0ee603ea85a533c4ef861871708525ef178f
4
- data.tar.gz: a16dccc9af5f0e92515fa7238eb129f4fc45533d3ff904c8f555043eca3ba53d
3
+ metadata.gz: 1fc728f6f0a3d2640bfb67ed6f62f5ea35417f05f7fb03fadc6ebb3adf55d256
4
+ data.tar.gz: 9adceb2e0fd319ff5af538a0b9c83537a89fa16f142db172bb220d66e95491e6
5
5
  SHA512:
6
- metadata.gz: 07a8d803c3130ecc851a464a008cad5cbd12155ec938750592e9a60732998e0efcbd3c18d171dc66ec90c4400c5ecfcef8a8e187331596517e7d86ee927bff15
7
- data.tar.gz: 3f2ae8eabec3559e2f40aaa182a04fb04f52521d61eff35c77a07e1469984c266b8b27076329715598c9b040cbbfff39cc5a1983b93df63f411a050e50bd2089
6
+ metadata.gz: c853c35a89f497d470fe0dd524a78e63b2ce5f356b97a33a55dc723517ce808e6fd7db26ed030c417199932bb916f12cede9f6a58b2f30c1d185ea256e640285
7
+ data.tar.gz: 79a8c59281249483f01b572570adf4eab80b026238924a0decb2ee06a460ea67736bd0cfc0c3d1217cf36dd93317aaefdc8828f1731dac1c6a9e4f1a9545050a
@@ -1,3 +1,10 @@
1
+ ## v0.5.0
2
+ [full changelog](http://github.com/ysato5654/histock-simplefilter/compare/v0.4.1...v0.5.0)
3
+
4
+ * support new request
5
+ - price to earning ratio
6
+ - price book ratio
7
+
1
8
  ## v0.4.1
2
9
  [full changelog](http://github.com/ysato5654/histock-simplefilter/compare/v0.4.0...v0.4.1)
3
10
 
data/README.md CHANGED
@@ -60,10 +60,8 @@ histock.monthly_revenue('2330') # code '2330' is TSMC
60
60
  #### Income Statement (損益表)
61
61
 
62
62
  ```rb
63
- require 'histock/simplefilter'
64
-
65
63
  histock = Histock::Simplefilter.new
66
- histock.income_statement('2330') # code '2330' is TSMC
64
+ histock.income_statement('2330')
67
65
  # [
68
66
  # ["年度/季別", "營收", "毛利", "營業利益", "稅前淨利", "稅後淨利"],
69
67
  # ["2019Q4", "317,237,065", "159,240,985", "124,243,722", "128,781,973", "116,078,194"],
@@ -82,10 +80,8 @@ histock.income_statement('2330') # code '2330' is TSMC
82
80
  #### 除權除息
83
81
 
84
82
  ```rb
85
- require 'histock/simplefilter'
86
-
87
83
  histock = Histock::Simplefilter.new
88
- histock.dividend_policy('2330') # code '2330' is TSMC
84
+ histock.dividend_policy('2330')
89
85
  # [
90
86
  # ["所屬年度", "發放年度", "除權日", "除息日", "除權息前股價", "股票股利", "現金股利", "EPS", "配息率", "現金殖利率", "扣抵稅率", "增資配股率", "增資認購價"],
91
87
  # ["2019", "2020", "", "06/18", "297.5", "0", "2.5", "13.32", "0.1877", "0.0084", "0", "0", "0"],
@@ -112,26 +108,50 @@ histock.dividend_policy('2330') # code '2330' is TSMC
112
108
  #### Profit Ratio (利潤比率)
113
109
 
114
110
  ```rb
115
- require 'histock/simplefilter'
116
-
117
111
  histock = Histock::Simplefilter.new
118
- histock.profit_ratio('2330') # code '2330' is TSMC
112
+ histock.profit_ratio('2330')
119
113
  ```
120
114
 
121
115
  #### Income Rate (報酬率)
122
116
 
123
117
  ```rb
124
- require 'histock/simplefilter'
125
-
126
118
  histock = Histock::Simplefilter.new
127
119
  # monthly data
128
- histock.income_rate('2330', 'month') # code '2330' is TSMC
120
+ histock.income_rate('2330', 'month')
129
121
  # quarterly data
130
122
  histock.income_rate('2330', 'quarter')
131
123
  # yearly data
132
124
  histock.income_rate('2330', 'year')
133
125
  ```
134
126
 
127
+ ### Corporate Value (企業價值)
128
+
129
+ #### PER (本益比)
130
+
131
+ ```rb
132
+ histock = Histock::Simplefilter.new
133
+ histock.price_to_earning_ratio('2330')
134
+ # [
135
+ # ["年度/月份", "本益比"],
136
+ # ["2020/06", "20.44"],
137
+ # [],
138
+ # :
139
+ # ]
140
+ ```
141
+
142
+ #### PBR (股價淨值比)
143
+
144
+ ```rb
145
+ histock = Histock::Simplefilter.new
146
+ histock.price_book_ratio('2330')
147
+ # [
148
+ # ["年度/月份", "股價淨值比"],
149
+ # ["2020/06", "4.89"],
150
+ # [],
151
+ # :
152
+ # ]
153
+ ```
154
+
135
155
  ### Request Lists (Method)
136
156
 
137
157
  | Category | Request (Ch) | Request (En) | Source URL |
@@ -143,5 +163,7 @@ histock.income_rate('2330', 'year')
143
163
  | 獲利能力 | 報酬率(單一季) | Income Rate | https://histock.tw/stock/financial.aspx?no=CODE&t=3&st=2&q=1 |
144
164
  | 獲利能力 | 報酬率(近四季) | Income Rate | https://histock.tw/stock/financial.aspx?no=CODE&t=3&st=2&q=2 |
145
165
  | 獲利能力 | 報酬率(年度) | Income Rate | https://histock.tw/stock/financial.aspx?no=CODE&t=3&st=2&q=3 |
166
+ | 企業價值 | 本益比 | Price-to-Earning Ratio | https://histock.tw/stock/financial.aspx?no=CODE&t=6&st=1 |
167
+ | 企業價值 | 股價淨值比 | Price-Book Ratio | https://histock.tw/stock/financial.aspx?no=CODE&t=6&st=2 |
146
168
 
147
169
  (note) You can fill real code number in 'CODE' field.
@@ -3,12 +3,14 @@ require File.expand_path(File.dirname(__FILE__)) + '/error'
3
3
  require File.expand_path(File.dirname(__FILE__)) + '/fetch/basic_financial_statements'
4
4
  require File.expand_path(File.dirname(__FILE__)) + '/fetch/dividend_policy'
5
5
  require File.expand_path(File.dirname(__FILE__)) + '/fetch/profitability'
6
+ require File.expand_path(File.dirname(__FILE__)) + '/fetch/corporate_value'
6
7
 
7
8
  module Histock
8
9
  module Fetch
9
10
  include BasicFinancialStatements
10
11
  include DividendPolicy
11
12
  include Profitability
13
+ include CorporateValue
12
14
 
13
15
  private
14
16
 
@@ -24,6 +26,10 @@ module Histock
24
26
  nodes = doc.xpath("//div[@class='row-stock']/div[@class='tb-outline']/div/table[@class='tb-stock tbBasic']")
25
27
  when :profit_ratio, :income_rate
26
28
  nodes = doc.xpath("//div[@class='row-stock w1060']/div[@class='tb-outline']/div/table[@class='tb-stock tbBasic']")
29
+ when :price_to_earning_ratio
30
+ nodes = doc.xpath("//div[@class='row-stock w740']/table[@class='tb-stock tb-outline tbBasic']")
31
+ when :price_book_ratio
32
+ nodes = doc.xpath("//div[@class='row-stock']/table[@class='tb-stock tb-outline tbBasic']")
27
33
  end
28
34
 
29
35
  raise InformationNotFound if nodes.empty?
@@ -36,7 +42,39 @@ module Histock
36
42
  end
37
43
 
38
44
  def parse_table query:, element:
39
- parse_tr(:query => query, :element => element)
45
+ if children_is_tbody(:element => element)
46
+ table = parse_tr(:query => query, :element => fetch_tbody(:element => element))
47
+ else
48
+ table = parse_tr(:query => query, :element => element)
49
+ end
50
+
51
+ case query
52
+ when :price_to_earning_ratio, :price_book_ratio
53
+ _table = Array.new
54
+
55
+ _table.concat([table[0][0..1]])
56
+
57
+ # remove header
58
+ table.slice!(0)
59
+
60
+ until table.flatten.empty? do
61
+ _table.concat(table.map { |e| e.slice!(0, 2) })
62
+ end
63
+
64
+ table = _table
65
+ end
66
+
67
+ table
68
+ end
69
+
70
+ def children_is_tbody element:
71
+ nodes = element.children
72
+
73
+ nodes.length.is_one? and nodes.first.name == 'tbody'
74
+ end
75
+
76
+ def fetch_tbody element:
77
+ element.children
40
78
  end
41
79
 
42
80
  # column
@@ -0,0 +1,15 @@
1
+ module Histock
2
+ module Fetch
3
+ module CorporateValue
4
+ def price_to_earning_ratio(code)
5
+ params = {:no => code, :t => 6, :st => 1}
6
+ parse(:query => __method__, :html => get('/financial.aspx', params))
7
+ end
8
+
9
+ def price_book_ratio(code)
10
+ params = {:no => code, :t => 6, :st => 2}
11
+ parse(:query => __method__, :html => get('/financial.aspx', params))
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  module Histock
2
2
  class Simplefilter
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: histock-simplefilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya Sato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-11 00:00:00.000000000 Z
11
+ date: 2020-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -103,6 +103,7 @@ files:
103
103
  - lib/histock/simplefilter/error.rb
104
104
  - lib/histock/simplefilter/fetch.rb
105
105
  - lib/histock/simplefilter/fetch/basic_financial_statements.rb
106
+ - lib/histock/simplefilter/fetch/corporate_value.rb
106
107
  - lib/histock/simplefilter/fetch/dividend_policy.rb
107
108
  - lib/histock/simplefilter/fetch/profitability.rb
108
109
  - lib/histock/simplefilter/version.rb