sorry_yahoo_finance 0.3.2 → 0.3.3
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 +4 -4
- data/lib/sorry_yahoo_finance/info.rb +87 -42
- data/lib/sorry_yahoo_finance/version.rb +1 -1
- data/lib/sorry_yahoo_finance.rb +1 -2
- data/lib/utils/ja.yml +31 -0
- data/spec/sorry_yahoo_finance_spec.rb +9 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f1b7245634866aac467151ea3e772b3aae128257
|
|
4
|
+
data.tar.gz: 598aac98a48657311a03f9aca40263a07a6919da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea9d56cf427dc1683dff717837464a9802034720a67716da8fcda67439506d5e84667883a261d1cf34d2a219e7e8e9aece61e477d111b47cdaf0b0f7f49d3261
|
|
7
|
+
data.tar.gz: 6b606496537778be9d85fc0e51fcf3e38df5344d3f3bc4cd107118a25cdf0fc252f5088e785c8a6a10c42c9d25207121aa58ee26ac6b3539694404ca0e5ad843
|
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
require 'utils/converter'
|
|
2
2
|
require 'utils/hash_accessor'
|
|
3
3
|
|
|
4
|
+
require 'yaml'
|
|
5
|
+
|
|
4
6
|
module SorryYahooFinance
|
|
5
7
|
class Info
|
|
8
|
+
INT_KEYS = [
|
|
9
|
+
:code,
|
|
10
|
+
:price,
|
|
11
|
+
:previousprice,
|
|
12
|
+
:opening,
|
|
13
|
+
:high,
|
|
14
|
+
:low,
|
|
15
|
+
:turnover,
|
|
16
|
+
:trading_volume,
|
|
17
|
+
:margin_buying,
|
|
18
|
+
:margin_selling,
|
|
19
|
+
:d_margin_buying,
|
|
20
|
+
:d_margin_selling,
|
|
21
|
+
:finish,
|
|
22
|
+
:capitalization,
|
|
23
|
+
:shares_outstanding,
|
|
24
|
+
:minimum_purchase,
|
|
25
|
+
:share_unit,
|
|
26
|
+
:yearly_high,
|
|
27
|
+
:yearly_low
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
FLOAT_KEYS = [
|
|
31
|
+
:margin_rate,
|
|
32
|
+
:dividend_yield,
|
|
33
|
+
:dps
|
|
34
|
+
]
|
|
35
|
+
|
|
6
36
|
extend HashAccessor
|
|
7
|
-
hash_accessor :values, :code, :name, :market, :industry, :price, :previousprice, :opening, :high, :low, :turnover, :trading_volume, :price_limit, :margin_buying, :margin_selling, :d_margin_buying, :d_margin_selling, :margin_rate, :chart_image
|
|
37
|
+
hash_accessor :values, :code, :name, :market, :industry, :price, :previousprice, :opening, :high, :low, :turnover, :trading_volume, :price_limit, :margin_buying, :margin_selling, :d_margin_buying, :d_margin_selling, :margin_rate, :capitalization, :shares_outstanding, :dividend_yield, :dps, :per, :pbr, :eps, :bps, :minimum_purchase, :share_unit, :yearly_high, :yearly_low, :chart_image
|
|
8
38
|
|
|
9
39
|
# TODO: 休場の時はアラート出したい
|
|
10
40
|
def initialize(code, date=nil)
|
|
@@ -23,44 +53,40 @@ module SorryYahooFinance
|
|
|
23
53
|
@values
|
|
24
54
|
end
|
|
25
55
|
|
|
56
|
+
def ja_values
|
|
57
|
+
Hash[
|
|
58
|
+
@values.to_a.map { |ary| [ja_rabels[ary[0]], ary[1]] }
|
|
59
|
+
]
|
|
60
|
+
end
|
|
61
|
+
|
|
26
62
|
def formalize_values
|
|
27
63
|
return_values = @values
|
|
28
64
|
|
|
29
|
-
|
|
30
|
-
int_keys = [
|
|
31
|
-
:code,
|
|
32
|
-
:price,
|
|
33
|
-
:previousprice,
|
|
34
|
-
:opening,
|
|
35
|
-
:high,
|
|
36
|
-
:low,
|
|
37
|
-
:turnover,
|
|
38
|
-
:trading_volume,
|
|
39
|
-
:margin_buying,
|
|
40
|
-
:margin_selling,
|
|
41
|
-
:d_margin_buying,
|
|
42
|
-
:d_margin_selling,
|
|
43
|
-
:finish
|
|
44
|
-
]
|
|
45
|
-
|
|
46
|
-
int_keys.each do |key|
|
|
65
|
+
INT_KEYS.each do |key|
|
|
47
66
|
if return_values[key].class == String
|
|
48
67
|
return_values[key] = return_values[key].delete(",").to_i
|
|
49
68
|
end
|
|
50
69
|
end
|
|
51
70
|
|
|
52
71
|
# to_range(str is like 183〜201)
|
|
53
|
-
price_limit = return_values[:price_limit]
|
|
54
|
-
price_limit.delete!(",")
|
|
55
|
-
price_limit =~ /(\d+)~(\d+)/
|
|
56
|
-
return_values[:price_limit] = Range.new($1.to_i,$2.to_i)
|
|
72
|
+
return_values[:price_limit] = return_values[:price_limit].to_range
|
|
57
73
|
|
|
58
74
|
# to_f
|
|
59
|
-
|
|
75
|
+
FLOAT_KEYS.each do |key|
|
|
76
|
+
return_values[key] = return_values[key].to_f
|
|
77
|
+
end
|
|
60
78
|
|
|
61
79
|
return_values
|
|
62
80
|
end
|
|
63
81
|
|
|
82
|
+
class ::String
|
|
83
|
+
def to_range
|
|
84
|
+
delete!(",")
|
|
85
|
+
self =~ /(\d+)~(\d+)/
|
|
86
|
+
Range.new($1.to_i,$2.to_i)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
64
90
|
private
|
|
65
91
|
|
|
66
92
|
def infos(code)
|
|
@@ -68,25 +94,40 @@ module SorryYahooFinance
|
|
|
68
94
|
html = Converter.execute(url)
|
|
69
95
|
previousprice, opening, high, low, turnover, trading_volume, price_limit = html.css('div.innerDate dd').map{|x| x.css('strong').inner_text }
|
|
70
96
|
margin_deal = html.css("div.ymuiDotLine div.yjMS dd.ymuiEditLink strong").map(&:text)
|
|
97
|
+
html.css('div#main div.main2colR div.chartFinance div.lineFi dl').map { |dl| dl.css('dd strong').text }
|
|
98
|
+
capitalization, shares_outstanding, dividend_yield, dps, per, pbr, eps, bps, minimum_purchase, share_unit, yearly_high, yearly_low = html.css('div#main div.main2colR div.chartFinance div.lineFi dl').map { |dl| dl.css('dd strong').text }
|
|
99
|
+
|
|
71
100
|
{
|
|
72
|
-
code:
|
|
73
|
-
name:
|
|
74
|
-
market:
|
|
75
|
-
industry:
|
|
76
|
-
price:
|
|
77
|
-
previousprice:
|
|
78
|
-
opening:
|
|
79
|
-
high:
|
|
80
|
-
low:
|
|
81
|
-
turnover:
|
|
82
|
-
trading_volume:
|
|
83
|
-
price_limit:
|
|
84
|
-
margin_buying:
|
|
85
|
-
margin_selling:
|
|
86
|
-
d_margin_buying:
|
|
87
|
-
d_margin_selling:
|
|
88
|
-
margin_rate:
|
|
89
|
-
|
|
101
|
+
code: code,
|
|
102
|
+
name: html.css('table.stocksTable th.symbol h1').inner_text,
|
|
103
|
+
market: html.css('div.stocksDtlWp dd')[0].content,
|
|
104
|
+
industry: html.css("div.stocksDtl dd.category a").text,
|
|
105
|
+
price: html.css('table.stocksTable td.stoksPrice')[1].content,
|
|
106
|
+
previousprice: previousprice,
|
|
107
|
+
opening: opening,
|
|
108
|
+
high: high,
|
|
109
|
+
low: low,
|
|
110
|
+
turnover: turnover,
|
|
111
|
+
trading_volume: trading_volume,
|
|
112
|
+
price_limit: price_limit,
|
|
113
|
+
margin_buying: margin_deal[0],
|
|
114
|
+
margin_selling: margin_deal[3],
|
|
115
|
+
d_margin_buying: margin_deal[1],
|
|
116
|
+
d_margin_selling: margin_deal[4],
|
|
117
|
+
margin_rate: margin_deal[2],
|
|
118
|
+
capitalization: capitalization,
|
|
119
|
+
shares_outstanding: shares_outstanding,
|
|
120
|
+
dividend_yield: dividend_yield,
|
|
121
|
+
dps: dps,
|
|
122
|
+
per: per,
|
|
123
|
+
pbr: pbr,
|
|
124
|
+
eps: eps,
|
|
125
|
+
bps: bps,
|
|
126
|
+
minimum_purchase: minimum_purchase,
|
|
127
|
+
share_unit: share_unit,
|
|
128
|
+
yearly_high: yearly_high,
|
|
129
|
+
yearly_low: yearly_low,
|
|
130
|
+
chart_image: html.css("div.styleChart img")[0][:src],
|
|
90
131
|
}
|
|
91
132
|
end
|
|
92
133
|
|
|
@@ -107,6 +148,10 @@ module SorryYahooFinance
|
|
|
107
148
|
}
|
|
108
149
|
end
|
|
109
150
|
|
|
151
|
+
def ja_rabels
|
|
152
|
+
YAML.load_file('lib/utils/ja.yml').inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
|
153
|
+
end
|
|
154
|
+
|
|
110
155
|
def yahoo_url(code)
|
|
111
156
|
"http://stocks.finance.yahoo.co.jp/stocks/detail/?code=#{code}"
|
|
112
157
|
end
|
data/lib/sorry_yahoo_finance.rb
CHANGED
|
@@ -33,11 +33,10 @@ module SorryYahooFinance
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
module GET
|
|
36
|
-
def execute(codes, date)
|
|
36
|
+
def self.execute(codes, date)
|
|
37
37
|
infos = codes.map { |code| Info.new(code, date) }
|
|
38
38
|
infos.count == 1 ? infos.first : infos
|
|
39
39
|
end
|
|
40
|
-
module_function :execute
|
|
41
40
|
end
|
|
42
41
|
end
|
|
43
42
|
Stock = SorryYahooFinance
|
data/lib/utils/ja.yml
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
code: 証券コード
|
|
2
|
+
name: 銘柄名
|
|
3
|
+
market: 取引市場
|
|
4
|
+
industry: 業種
|
|
5
|
+
price: 株価
|
|
6
|
+
previousprice: 前日終値
|
|
7
|
+
opening: 始値
|
|
8
|
+
high: 高値
|
|
9
|
+
low: 安値
|
|
10
|
+
turnover: 出来高
|
|
11
|
+
trading_volume: 売買代金
|
|
12
|
+
price_limit: 値幅制限
|
|
13
|
+
margin_buying: 信用買残
|
|
14
|
+
margin_selling: 信用売残
|
|
15
|
+
d_margin_buying: 信用買残前週比
|
|
16
|
+
d_margin_selling: 信用売残前週比
|
|
17
|
+
margin_rate: 貸借倍率
|
|
18
|
+
margin_rate: 貸借倍率
|
|
19
|
+
capitalization: 時価総額
|
|
20
|
+
shares_outstanding: 発行済株式数
|
|
21
|
+
dividend_yield: 配当利回り(会社予想)
|
|
22
|
+
dps: 1株配当(会社予想)
|
|
23
|
+
per: PER(会社予想)
|
|
24
|
+
pbr: PBR(実績)
|
|
25
|
+
eps: EPS(会社予想)
|
|
26
|
+
bps: BPS(実績)
|
|
27
|
+
minimum_purchase: 最低購入代金
|
|
28
|
+
share_unit: 単元株数
|
|
29
|
+
yearly_high: 年初来高値
|
|
30
|
+
yearly_low: 年初来安値
|
|
31
|
+
chart_image: チャート図
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
|
|
2
|
+
require 'pry'
|
|
3
3
|
describe SorryYahooFinance do
|
|
4
4
|
|
|
5
5
|
it 'should have a version number' do
|
|
@@ -33,5 +33,13 @@ describe SorryYahooFinance do
|
|
|
33
33
|
describe 'Info' do
|
|
34
34
|
subject { SorryYahooFinance::GET(8058) }
|
|
35
35
|
specify { expect(subject.formalize_values).to be_a(Hash) }
|
|
36
|
+
specify { expect(subject.ja_values).to be_a(Hash) }
|
|
37
|
+
specify do
|
|
38
|
+
expect(subject.ja_values.keys).to eq(
|
|
39
|
+
[
|
|
40
|
+
"証券コード", "銘柄名", "取引市場", "業種", "株価", "前日終値", "始値", "高値", "安値", "出来高", "売買代金", "値幅制限", "信用買残", "信用売残", "信用買残前週比", "信用売残前週比", "貸借倍率", "時価総額", "発行済株式数", "配当利回り(会社予想)", "1株配当(会社予想)", "PER(会社予想)", "PBR(実績)", "EPS(会社予想)", "BPS(実績)", "最低購入代金", "単元株数", "年初来高値", "年初来安値", "チャート図"
|
|
41
|
+
]
|
|
42
|
+
)
|
|
43
|
+
end
|
|
36
44
|
end
|
|
37
45
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sorry_yahoo_finance
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- gogotanaka
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: nokogiri
|
|
@@ -117,6 +117,7 @@ files:
|
|
|
117
117
|
- lib/utils/all_stock_codes.rb
|
|
118
118
|
- lib/utils/converter.rb
|
|
119
119
|
- lib/utils/hash_accessor.rb
|
|
120
|
+
- lib/utils/ja.yml
|
|
120
121
|
- sorry_yahoo_finance.gemspec
|
|
121
122
|
- spec/sorry_yahoo_finance_spec.rb
|
|
122
123
|
- spec/spec_helper.rb
|