sorry_yahoo_finance 0.3.3 → 0.4.1

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: f1b7245634866aac467151ea3e772b3aae128257
4
- data.tar.gz: 598aac98a48657311a03f9aca40263a07a6919da
3
+ metadata.gz: e8898c990e56d86010112716e8029ef7c26fdcec
4
+ data.tar.gz: 8b1fddc71d55b48499e73246d0fa6a5a72f11f7f
5
5
  SHA512:
6
- metadata.gz: ea9d56cf427dc1683dff717837464a9802034720a67716da8fcda67439506d5e84667883a261d1cf34d2a219e7e8e9aece61e477d111b47cdaf0b0f7f49d3261
7
- data.tar.gz: 6b606496537778be9d85fc0e51fcf3e38df5344d3f3bc4cd107118a25cdf0fc252f5088e785c8a6a10c42c9d25207121aa58ee26ac6b3539694404ca0e5ad843
6
+ metadata.gz: f78429d2badf1c25e0ad4057fb4b11f328eacc067d6e36b25ee082a2ea1c0cad7aa10cb0e511e299b1352f6ef11af77d6e3f509460d63ed5ef3d7ee43f929b73
7
+ data.tar.gz: dac1bf9b291ad8c176eb2dfa57075826055d37c9d62495b967121317e6b74ba7b0a4f291dfa29e76c4660d49362ad682578d0407c16a0f99df3032177cca0566
data/.gitignore CHANGED
@@ -1,19 +1,14 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.DS_Store
19
- /vendor/bundle
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml CHANGED
@@ -1,3 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
3
+ - 2.2.0
4
+ - 2.1.4
5
+ - 2.0.0
6
+ notifications:
7
+ email: false
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in sorry_yahoo_finance.gemspec
4
2
  gemspec
3
+
4
+ gem 'pry'
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 GoGoTanaka
1
+ Copyright (c) 2015 GoGoTanaka
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,216 +1,213 @@
1
1
  株式の情報取得するGem作ったよ!
2
2
 
3
- # 2014/3/21 アップデートしたよ!
3
+ # バグ報告頂いてから24時間以内に必ず直します。(という気概です)
4
4
  --------
5
5
 
6
- https://github.com/gogotanaka/sorry_yahoo_finance
7
-
8
- https://rubygems.org/gems/sorry_yahoo_finance
9
-
10
- 株式の各種データをひっぱってきたいと思い、Gemを探したが以外となかったので作ってみた。
11
-
12
6
  Yahoo!Japanファイナンス(http://finance.yahoo.co.jp/)
13
7
 
14
- から株の情報をひっぱてきます。ごめんなさい。Yahoo!
8
+ から株の情報をひっぱて適切なデータ型(Integer, Float, Range..). ごめんなさい、Yahoo!
15
9
 
16
10
  今の所
17
-
18
- * 証券コード
19
- * 市場
20
- * 業種
21
- * 株価
22
- * 前日終値
23
- * 始値
24
- * 高値
25
- * 安値
26
- * 出来高
27
- * 売買代金
28
- * 値幅制限
29
- * 信用買残
30
- * 信用買残前週比
31
- * 信用売残
32
- * 信用売残前週比
33
- * 貸借倍率
34
-
35
- を取ってきます。余裕があったらもっと増やします。
36
-
37
- 更新履歴
38
- --------
39
- * 0.1.0 (2014-02-15)
40
- * 一応形にした
41
-
42
- * 0.2.0 (2014-02-20)
43
- * いい感じにした
44
- * 0.3.0 (2014-03-21)
45
- * もっといい感じにした
46
-
47
-
48
-
49
- --------
50
-
51
- https://github.com/gogotanaka/sorry_yahoo_finance
52
-
53
- #SorryYahooFinance::GET
54
-
55
- ### 証券コードと日付を引数に SorryYahooFinance::Info のオブジェクト(該当株式の情報)の配列またはそれ自身を返す。
56
-
57
- 証券コードのみ指定した場合はその時点での情報をとってくる。
58
-
59
- 日付の渡し方は2パターン用意してある。
60
-
61
- ```ruby:ex1.rb
62
- SorryYahooFinance::GET(8058)
63
- => #<SorryYahooFinance::Info:0x007ff7db73cfa0
64
- @values=
65
- {:code=>"8058",
66
- :name=>"三菱商事(株)",
67
- :market=>"東証1部 ",
68
- :industry=>"卸売業",
69
- :price=>"1,863",
70
- :previousprice=>"1,876",
71
- :opening=>"1,880",
72
- :high=>"1,893",
73
- :low=>"1,860",
74
- :turnover=>"7,359,200",
75
- :trading_volume=>"13,763,108",
76
- :price_limit=>"1,476~2,276",
77
- :margin_buying=>"6,763,500",
78
- :margin_selling=>"307,400",
79
- :d_margin_buying=>"+885,500",
80
- :d_margin_selling=>"-181,100",
81
- :margin_rate=>"22",
82
- :chart_image=>"http://gchart.yahoo.co.jp/f?s=8058.T"}>
83
-
84
-
85
-
86
- SorryYahooFinance::GET(8606, Date(2014, 3, 20))
87
- => #<SorryYahooFinance::Info:0x007fcb2b6d53c8 ...
88
-
89
-
90
- SorryYahooFinance::GET(8058, 2014, 3, 20)
91
- => #<SorryYahooFinance::Info:0x007fcb36260030 ...
92
-
93
11
  ```
94
-
95
-
96
- ちなみに SorryYahooFinance が長過ぎて無理な人のために Stock というエイリアスを張ってある。
97
-
98
- ```ruby:ex2.rb
99
- Stock::GET(8058, Date.new(2008, 9, 15))
100
- => #<SorryYahooFinance::Info:0x007fcb36260030>
101
-
102
- Stock::GET(8606)
103
- => #<SorryYahooFinance::Info:0x007fcb2b6d53c8>
12
+ [
13
+ "証券コード",
14
+ "銘柄名",
15
+ "取引市場",
16
+ "業種",
17
+ "株価",
18
+ "前日終値",
19
+ "始値",
20
+ "高値",
21
+ "安値",
22
+ "出来高",
23
+ "売買代金",
24
+ "値幅制限",
25
+ "信用買残",
26
+ "信用売残",
27
+ "信用買残前週比",
28
+ "信用売残前週比",
29
+ "貸借倍率",
30
+ "時価総額",
31
+ "発行済株式数",
32
+ "配当利回り(会社予想)",
33
+ "1株配当(会社予想)",
34
+ "PER(会社予想)",
35
+ "PBR(実績)",
36
+ "EPS(会社予想)",
37
+ "BPS(実績)",
38
+ "最低購入代金",
39
+ "単元株数",
40
+ "年初来高値",
41
+ "年初来安値",
42
+ "チャート図"
43
+ ]
104
44
  ```
105
45
 
46
+ を取ってきます。余裕があったらもっと増やします。
106
47
 
107
- 証券コードを複数渡した場合はSorryYahooFinance::Infoオブジェクトの配列を返す。
108
-
109
- ```ruby:ex3.rb
110
- SorryYahooFinance::GET([8606,8058])
111
- => [#<SorryYahooFinance::Info:0x007fcb2e4816a0 ...>, #<SorryYahooFinance::Info:0x007fcb30a17e78 ... >]
112
-
113
-
114
- SorryYahooFinance::GET([8606,8058], Date.new(2014, 3, 20))
115
- => [#<SorryYahooFinance::Info:0x007fcb2e4816a0 ...>, #<SorryYahooFinance::Info:0x007fcb30a17e78 ... >]
116
-
117
-
118
- SorryYahooFinance::GET([8606,8058], 2014, 3, 20)
119
- => [#<SorryYahooFinance::Info:0x007fcb2e4816a0 ...>, #<SorryYahooFinance::Info:0x007fcb30a17e78 ... >]
120
-
121
-
122
- ```
123
-
124
- 証券コード、その配列の代わりに:allというシンボルを渡せば全株式のSorryYahooFinance::Infoオブジェクトを取ってくる。
125
-
126
- 全株式の指すところはこのあたり参照
127
-
128
- (http://www.tse.or.jp/market/data/listed_companies/)
129
-
130
- ```ruby:ex4.rb
131
- SorryYahooFinance::GET(:all)
132
- => .....(略)
133
- ```
134
-
135
-
136
-
137
-
138
- # SorryYahooFinance::Infoクラスのあれこれ
139
-
140
- SorryYahooFinance::GETによって作られるSorryYahooFinance::Infoについて
141
-
48
+ インストール
49
+ --------
142
50
 
51
+ $ gem install sorry_yahoo_finance
143
52
 
144
- ```ruby:ex5.rb
145
- info = SorryYahooFinance::GET(8411)
53
+ または
146
54
 
147
- info.values
148
- => {:code=>"8411",
149
- :name=>"(株)みずほフィナンシャルグループ",
150
- :market=>"東証1部",
151
- :industry=>"銀行業",
152
- :price=>"212",
153
- :previousprice=>"218",
154
- :opening=>"218",
155
- :high=>"218",
156
- :low=>"211",
157
- :turnover=>"197,084,500",
158
- :trading_volume=>"42,334,350",
159
- :price_limit=>"138~298",
160
- :margin_buying=>"320,352,600",
161
- :margin_selling=>"13,355,900",
162
- :d_margin_buying=>"+15,929,300",
163
- :d_margin_selling=>"-4,316,500",
164
- :margin_rate=>"23.99",
165
- :chart_image=>"http://gchart.yahoo.co.jp/f?s=8411.T"}
166
- ```
55
+ $ echo "gem 'sorry_yahoo_finance'" >> Gemfile
56
+ $ bundle
167
57
 
168
- SorryYahooFinance::Info#market などでそれぞれの情報
58
+ でGemをインストール
169
59
 
170
- ```ruby:ex6.rb
171
- info.market
172
- => "東証1部"
173
- ```
60
+ 使い方
61
+ --------
174
62
 
63
+ `YahooFinance.find`で株価の情報をHashまたはHashの配列で受け取る.
64
+
65
+
66
+ ```rb
67
+ # 証券コードを1つ指定
68
+ YahooFinance.find(8058)
69
+ =>{
70
+ "証券コード"=>8058,
71
+ "銘柄名"=>"三菱商事(株)",
72
+ "取引市場"=>"東証1部",
73
+ "業種"=>"卸売業",
74
+ "株価"=>2030,
75
+ "前日終値"=>2037,
76
+ "始値"=>2015,
77
+ "高値"=>2031,
78
+ "安値"=>2000,
79
+ "出来高"=>6705900,
80
+ "売買代金"=>13495988,
81
+ "値幅制限"=>1537..2537,
82
+ "信用買残"=>4071100,
83
+ "信用売残"=>592600,
84
+ "信用買残前週比"=>574300,
85
+ "信用売残前週比"=>-167100,
86
+ "貸借倍率"=>6.87,
87
+ "時価総額"=>3297607,
88
+ "発行済株式数"=>1624036751,
89
+ "配当利回り(会社予想)"=>3.45,
90
+ "1株配当(会社予想)"=>70.0,
91
+ "PER(会社予想)"=>"(連) 8.28",
92
+ "PBR(実績)"=>"(連) 0.57",
93
+ "EPS(会社予想)"=>"\n(連) 245.17",
94
+ "BPS(実績)"=>"\n(連) 3,568.72",
95
+ "最低購入代金"=>203050,
96
+ "単元株数"=>100,
97
+ "年初来高値"=>2356,
98
+ "年初来安値"=>1767,
99
+ "チャート図"=>"http://chart.yahoo.co.jp/?code=8058.T&tm=1d&size=e&vip=off"
100
+ }
101
+
102
+ # 証券コードを複数指定
103
+ YahooFinance.find(8606, 8058)
104
+ =>[
105
+ {
106
+ "証券コード"=>8606,
107
+ "銘柄名"=>"みずほ証券(株)",
108
+ "取引市場"=>"東証1部",
109
+ "業種"=>"証券業",
110
+ "株価"=>210,
111
+ ...
112
+ },
113
+ {
114
+ "証券コード"=>8058,
115
+ "銘柄名"=>"三菱商事(株)",
116
+ "取引市場"=>"東証1部",
117
+ "業種"=>"卸売業",
118
+ "株価"=>1880,
119
+ ...
120
+ }
121
+ ]
122
+
123
+
124
+ # 日付を指定、その1
125
+ YahooFinance.find(8058, date: Date.new(2014, 3, 20))
126
+ =>{
127
+ "証券コード"=>8058,
128
+ "銘柄名"=>"三菱商事(株)",
129
+ "取引市場"=>"東証1部",
130
+ "業種"=>"卸売業",
131
+ "始値"=>1880,
132
+ "高値"=>1893,
133
+ "安値"=>1860,
134
+ "終値"=>1863
135
+ }
136
+
137
+ # 日付を指定、その2
138
+ YahooFinance.find(8058, date: [2014, 3, 20])
139
+ =>{
140
+ "証券コード"=>8058,
141
+ "銘柄名"=>"三菱商事(株)",
142
+ "取引市場"=>"東証1部",
143
+ "業種"=>"卸売業",
144
+ "始値"=>1880,
145
+ "高値"=>1893,
146
+ "安値"=>1860,
147
+ "終値"=>1863
148
+ }
149
+
150
+ # 日付を複数指定
151
+ * `format: :json`を指定しない場合はdateの値はDateオブジェクトになります.
152
+ * 証券コードと日付をどちらも複数していする事は出来ません.(2015-1-14現在)
153
+ JSON.parse(YahooFinance.find(8058, date: Date.new(2014, 3, 28) .. Date.new(2014, 4, 3), format: :json, lang: :en))
154
+ =>{
155
+ "code"=>8058,
156
+ "name"=>"三菱商事(株)",
157
+ "market"=>"東証1部",
158
+ "industry"=>"卸売業",
159
+ "prices"=>
160
+ [
161
+ {"opening"=>1863, "high"=>1879, "low"=>1838, "finish"=>1879, "turnover"=>5558500, "date"=>"2014-03-28"},
162
+ {"opening"=>1891, "high"=>1920, "low"=>1891, "finish"=>1916, "turnover"=>6580800, "date"=>"2014-03-31"},
163
+ {"opening"=>1915, "high"=>1925, "low"=>1903, "finish"=>1919, "turnover"=>4873600, "date"=>"2014-04-01"},
164
+ {"opening"=>1923, "high"=>1944, "low"=>1910, "finish"=>1921, "turnover"=>6388600, "date"=>"2014-04-02"},
165
+ {"opening"=>1935, "high"=>1943, "low"=>1921, "finish"=>1930, "turnover"=>5344400, "date"=>"2014-04-03"}
166
+ ]
167
+ }
168
+
169
+
170
+
171
+ # ラベルを英語で
172
+ YahooFinance.find(8606, lang: :en)
173
+ =>{
174
+ :code=>8606,
175
+ :name=>"みずほ証券(株)",
176
+ :market=>"東証1部",
177
+ :industry=>"証券業",
178
+ :price=>0,
179
+ :previousprice=>165
180
+ ...
181
+ }
182
+
183
+
184
+ # フォーマットをjsonで
185
+ YahooFinance.find(8606, format: :json, lang: :en)
186
+ => "{\"code\":8606,\"name\":\"みずほ証券(株)\",\"market\":\"東証1部\",\"industry\":\"証券業\",\"price\":0,\"previousprice\":165,\"opening\":0,\"high\":0,\"low\":0,\"turnover\":0,\"trading_volume\":0,\"price_limit\":\"0..0\",\"margin_buying\":1070000,\"margin_selling\":90000,\"d_margin_buying\":-3343000,\"d_margin_selling\":-748000,\"margin_rate\":11.89,\"capitalization\":262629,\"shares_outstanding\":1591688683,\"dividend_yield\":0.0,\"dps\":0.0,\"per\":\"(連) ---\",\"pbr\":\"(連) 0.49\",\"eps\":\"\\n---\",\"bps\":\"\\n(連) 334.82\",\"minimum_purchase\":165000,\"share_unit\":1000,\"yearly_high\":254,\"yearly_low\":162,\"chart_image\":\"http://chart.yahoo.co.jp/?code=8606.T&tm=1d&size=e&vip=off\"}"
187
+
188
+
189
+ YahooFinance.find(8604, 8058, date: Date.new(2014, 12, 1), lang: :en)
190
+ =>[
191
+ {
192
+ :code=>8604,
193
+ :name=>"野村ホールディングス(株)",
194
+ :market=>"東証1部",
195
+ :industry=>"証券業",
196
+ :opening=>716,
197
+ :high=>726,
198
+ :low=>710,
199
+ :finish=>718
200
+ },
201
+ {
202
+ :code=>8058,
203
+ :name=>"三菱商事(株)",
204
+ :market=>"東証1部",
205
+ :industry=>"卸売業",
206
+ :opening=>2260,
207
+ :high=>2278,
208
+ :low=>2215,
209
+ :finish=>2222
210
+ }
211
+ ]
175
212
 
176
- SorryYahooFinance::Info#formalize_values でvaluesの各値をFixnumやRangeにしたものを返す。
177
-
178
- ```ruby:ex7.rb
179
- info.formalize_values
180
- => {:code=>8411,
181
- :name=>"(株)みずほフィナンシャルグループ",
182
- :market=>"東証1部",
183
- :industry=>"銀行業",
184
- :price=>201,
185
- :previousprice=>203,
186
- :opening=>203,
187
- :high=>204,
188
- :low=>200,
189
- :turnover=>111785700,
190
- :trading_volume=>22552224,
191
- :price_limit=>123..283,
192
- :margin_buying=>370732000,
193
- :margin_selling=>7085000,
194
- :d_margin_buying=>36113200,
195
- :d_margin_selling=>-962200,
196
- :margin_rate=>52.33,
197
- :chart_image=>"http://gchart.yahoo.co.jp/f?s=8411.T"}
198
213
  ```
199
-
200
- LICENSE
201
- -------
202
- (The MIT License)
203
-
204
- Copyright (c) 2014 GoGoTanaka
205
-
206
- Permission is hereby granted, free of charge, to any person obtaining a copy
207
- of this software and associated documentation files (the "Software"), to deal
208
- in the Software without restriction, including without limitation the rights
209
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
210
- copies of the Software, and to permit persons to whom the Software is
211
- furnished to do so, subject to the following conditions:
212
-
213
- The above copyright notice and this permission notice shall be included in
214
- all copies or substantial portions of the Software.
215
-
216
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
data/Rakefile CHANGED
@@ -1,6 +1,9 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/test_*.rb']
7
+ end
5
8
 
6
- task :default => :spec
9
+ task :default => :test
@@ -0,0 +1,134 @@
1
+ require "sorry_yahoo_finance/http_client"
2
+ require "sorry_yahoo_finance/decorator"
3
+
4
+ module SorryYahooFinance
5
+ class Acquirer
6
+ include Decorator
7
+
8
+ attr_reader :stocks
9
+
10
+ def initialize(codes, date_or_ary_range_range)
11
+ dates = build_date(date_or_ary_range_range)
12
+ @stocks = if codes.count == 1
13
+ [get_one(codes.first, dates)]
14
+ else
15
+ get_some(codes, dates)
16
+ end
17
+ end
18
+
19
+ def get_one(code, dates)
20
+ if dates
21
+ scrape_with_dates(code, dates)
22
+ else
23
+ scrape_without_date(code)
24
+ end
25
+ end
26
+
27
+ def get_some(codes, dates)
28
+ codes.map do |code|
29
+ get_one(code, dates)
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def scrape_with_dates(code, dates)
36
+ # TODO: ugly..
37
+ case dates
38
+ when Date
39
+ scrape_with_date(code, dates)
40
+ when Array
41
+ meta_info = scrape_with_date(code, dates[0])
42
+ prices = dates.map do |date|
43
+ scrape_with_date(code, date).select { |k, v| [:opening, :high, :low, :finish, :turnover].include? k }.merge({date: date})
44
+ end
45
+ {
46
+ code: meta_info[:code],
47
+ name: meta_info[:name],
48
+ market: meta_info[:market],
49
+ industry: meta_info[:industry],
50
+ prices: prices
51
+ }
52
+ end
53
+ end
54
+
55
+ def scrape_with_date(code, date)
56
+ year, month, day = date.strftime("%Y,%m,%d").split(",")
57
+ month.delete!("0")
58
+ url = "http://info.finance.yahoo.co.jp/history/?code=#{code}.T&sy=#{year}&sm=#{month}&sd=#{day}&ey=#{year}&em=#{month}&ed=#{day}&tm=d"
59
+ html = HttpClient.get(url)
60
+ tds = html.xpath("(//div[@id='main']//table)[2]//td")
61
+ opening, high, low, finish, turnover = tds[1..5].map(&:text)
62
+ {
63
+ code: code,
64
+ name: html.css('table.stocksTable th.symbol h1').inner_text,
65
+ market: html.css('div#ddMarketSelect span.stockMainTabName').inner_text,
66
+ industry: html.css("div.stocksDtl dd.category a").text,
67
+ opening: opening,
68
+ high: high,
69
+ low: low,
70
+ finish: finish,
71
+ turnover: turnover
72
+ }
73
+ end
74
+
75
+ def scrape_without_date(code)
76
+ # TODO: ugly..
77
+ url = "http://stocks.finance.yahoo.co.jp/stocks/detail/?code=#{code}"
78
+ html = HttpClient.get(url)
79
+
80
+ previousprice, opening, high, low, turnover, trading_volume, price_limit = html.css('div.innerDate dd').map{|x| x.css('strong').inner_text }
81
+ margin_deal = html.css("div.ymuiDotLine div.yjMS dd.ymuiEditLink strong").map(&:text)
82
+ html.css('div#main div.main2colR div.chartFinance div.lineFi dl').map { |dl| dl.css('dd strong').text }
83
+ 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 }
84
+
85
+ {
86
+ code: code,
87
+ name: html.css('table.stocksTable th.symbol h1').inner_text,
88
+ market: html.css('div#ddMarketSelect span.stockMainTabName').inner_text,
89
+ industry: html.css("div.stocksDtl dd.category a").text,
90
+ price: html.css('table.stocksTable td.stoksPrice')[1].content,
91
+ previousprice: previousprice,
92
+ opening: opening,
93
+ high: high,
94
+ low: low,
95
+ turnover: turnover,
96
+ trading_volume: trading_volume,
97
+ price_limit: price_limit,
98
+ margin_buying: margin_deal[0],
99
+ margin_selling: margin_deal[3],
100
+ d_margin_buying: margin_deal[1],
101
+ d_margin_selling: margin_deal[4],
102
+ margin_rate: margin_deal[2],
103
+ capitalization: capitalization,
104
+ shares_outstanding: shares_outstanding,
105
+ dividend_yield: dividend_yield,
106
+ dps: dps,
107
+ per: per,
108
+ pbr: pbr,
109
+ eps: eps,
110
+ bps: bps,
111
+ minimum_purchase: minimum_purchase,
112
+ share_unit: share_unit,
113
+ yearly_high: yearly_high,
114
+ yearly_low: yearly_low,
115
+ chart_image: html.css("div.styleChart img")[0][:src],
116
+ }
117
+ end
118
+
119
+ def build_date(date_or_ary_range)
120
+ return unless date_or_ary_range
121
+
122
+ case date_or_ary_range
123
+ when Array
124
+ fail 'Should supply three value for year, month and day' unless date_or_ary_range.count == 3
125
+ Date.new(*date_or_ary_range)
126
+ when Date
127
+ date_or_ary_range
128
+ when Range
129
+ date_or_ary_range.to_a
130
+ end
131
+ end
132
+
133
+ end
134
+ end
@@ -0,0 +1,59 @@
1
+ require 'json'
2
+
3
+ require "sorry_yahoo_finance/utils/decorate_cons"
4
+
5
+ module SorryYahooFinance
6
+ module Decorator
7
+ include DecorateCons
8
+
9
+ def output(lang, format)
10
+ case lang
11
+ when :ja
12
+ @stocks.map! { |stock_hash| to_ja_key(stock_hash) }
13
+ end
14
+
15
+ @stocks.map! { |stock_hash| formalize_values(stock_hash) }
16
+
17
+ case format
18
+ when :hash
19
+ when :json
20
+ @stocks.map! &:to_json
21
+ end
22
+
23
+ @stocks
24
+ end
25
+
26
+ private
27
+ def to_ja_key(stock_hash)
28
+ Hash[
29
+ stock_hash.to_a.map { |k, v| [JA_RABEL_HASH[k], v] }
30
+ ]
31
+ end
32
+
33
+ def formalize_values(stock_hash)
34
+ Hash[
35
+ stock_hash.map do |key, value|
36
+ formated_value = if value.nil?
37
+ nil
38
+ elsif INT_KEYS.include?(key)
39
+ value.delete(",").to_i
40
+ elsif FLOAT_KEYS.include?(key)
41
+ value.to_f
42
+ elsif key == :price_limit
43
+ value.delete!(",")
44
+ value =~ /(\d+)~(\d+)/
45
+ Range.new($1.to_i,$2.to_i)
46
+ elsif key == :prices
47
+ prices = stock_hash[:prices]
48
+ prices.select! {|price| price[:turnover] }
49
+ prices.map { |price| formalize_values(price) }
50
+ else
51
+ value
52
+ end
53
+ [key, formated_value]
54
+ end
55
+ ]
56
+ end
57
+
58
+ end
59
+ end