cstock 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/cstock +2 -2
- data/cstock.gemspec +2 -2
- data/lib/cstock/stock.rb +19 -5
- data/lib/cstock/version.rb +1 -1
- data/spec/cstock_spec.rb +24 -3
- metadata +9 -10
- data/cstock-0.1.0.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa7fb1e0d445516a141f448825634dc47d7aba2f
|
4
|
+
data.tar.gz: ba2c88cb28745dc7108b831144d53bdb3fdd4e12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a4a4d642357bd4ac63fa29292640c5114b773e5ab627e9102ae344e7311d93bb6bb0614ff8f8e58a524e175b6b377234506afd961b7bcd2b7a1d33915ff7554
|
7
|
+
data.tar.gz: 7637e232f51818a32f7f935d74eabbc2aff57a37fc455721840afcb8d2714c51705a0dea0cc521d94b77cc42e74e022290a3b12fe0e19308e785d0fe74e764a9
|
data/README.md
CHANGED
data/bin/cstock
CHANGED
@@ -4,11 +4,11 @@ require 'cstock'
|
|
4
4
|
|
5
5
|
if ARGV.count != 1
|
6
6
|
puts "With the given stock code quote its infomation."
|
7
|
-
puts "usage: cstock
|
7
|
+
puts "usage: cstock 600000"
|
8
8
|
exit
|
9
9
|
end
|
10
10
|
|
11
11
|
code = ARGV[0]
|
12
12
|
|
13
|
-
stock = CStock::Stock.
|
13
|
+
stock = CStock::Stock.new(code)
|
14
14
|
stock.description
|
data/cstock.gemspec
CHANGED
@@ -17,6 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = %w(cstock)
|
18
18
|
s.homepage = 'https://github.com/astonfu/cstock'
|
19
19
|
|
20
|
-
s.add_runtime_dependency 'rest-client'
|
21
|
-
s.add_development_dependency 'rspec'
|
20
|
+
s.add_runtime_dependency 'rest-client', '~> 1.6'
|
21
|
+
s.add_development_dependency 'rspec', '~> 3.2'
|
22
22
|
end
|
data/lib/cstock/stock.rb
CHANGED
@@ -18,20 +18,34 @@ module CStock
|
|
18
18
|
__send__(:alias_method, FIELDS_ZH[index].to_sym, field.to_sym)
|
19
19
|
end
|
20
20
|
|
21
|
-
def initialize(stock_code, data)
|
21
|
+
def initialize(stock_code, data=nil)
|
22
22
|
@code = stock_code
|
23
|
-
|
23
|
+
data = self.class.quote(stock_code) if data == nil
|
24
24
|
FIELDS[1..-1].each_with_index do |field, index|
|
25
25
|
instance_variable_set("@#{field}", (data[index].nil? ? nil : data[index]))
|
26
26
|
end
|
27
|
+
yield self if block_given?
|
27
28
|
end
|
28
29
|
|
30
|
+
|
29
31
|
def description
|
30
32
|
FIELDS_ZH.each do |field|
|
31
33
|
puts field + " : " + self.send(field)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
37
|
+
def refresh
|
38
|
+
self.class.refresh(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.refresh(stock)
|
42
|
+
quote(stock.code) do |data|
|
43
|
+
FIELDS[1..-1].each_with_index do |field, index|
|
44
|
+
stock.instance_variable_set("@#{field}", (data[index].nil? ? nil : data[index]))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
35
49
|
PREFIX_URL = "http://hq.sinajs.cn/list="
|
36
50
|
def self.quote(stock_code)
|
37
51
|
parsed_stock_code = parse_stock_code(stock_code)
|
@@ -39,9 +53,9 @@ module CStock
|
|
39
53
|
|
40
54
|
RestClient::Request.execute(:url => url, :method => :get) do |response|
|
41
55
|
if response.code == 200
|
42
|
-
|
43
|
-
yield(
|
44
|
-
return
|
56
|
+
data = parse(response.force_encoding("GBK").encode("UTF-8"))
|
57
|
+
yield(data) if block_given?
|
58
|
+
return data
|
45
59
|
else
|
46
60
|
nil
|
47
61
|
end
|
data/lib/cstock/version.rb
CHANGED
data/spec/cstock_spec.rb
CHANGED
@@ -2,8 +2,8 @@ require 'cstock'
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe CStock::Stock do
|
5
|
-
describe '
|
6
|
-
stock = CStock::Stock.
|
5
|
+
describe 'initialize' do
|
6
|
+
stock = CStock::Stock.new('600000') do |s|
|
7
7
|
puts "***" + s.name
|
8
8
|
end
|
9
9
|
stock.description
|
@@ -16,4 +16,25 @@ describe CStock::Stock do
|
|
16
16
|
expect(stock.code).to eq("600000")
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
|
+
describe "refresh" do
|
21
|
+
before :each do
|
22
|
+
@s = CStock::Stock.new('600000', %w(name open_price yesterday_close_price cur_price high_price low_price bid_price_1 ask_price_1 volume turnover
|
23
|
+
bid_volume_1 bid_price_1 bid_volume_2 bid_price_2 bid_volume_3 bid_price_3 bid_volume_4 bid_price_4 bid_volume_5 bid_price_5
|
24
|
+
ask_volume_1 ask_price_1 ask_volume_2 ask_price_2 ask_volume_3 ask_price_3 ask_volume_4 ask_price_4 ask_volume_5 ask_price_5
|
25
|
+
date time))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "class method update stock attr" do
|
29
|
+
expect(@s.name).to eq("name")
|
30
|
+
CStock::Stock.refresh(@s)
|
31
|
+
expect(@s.name).to eq('浦发银行')
|
32
|
+
end
|
33
|
+
|
34
|
+
it "instance method update stock attr" do
|
35
|
+
expect(@s.name).to eq("name")
|
36
|
+
@s.refresh
|
37
|
+
expect(@s.name).to eq('浦发银行')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cstock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aston Fu
|
@@ -14,30 +14,30 @@ dependencies:
|
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.2'
|
41
41
|
description: A ruby gem that get chinese stock infomation.
|
42
42
|
email: im@fuhao.im
|
43
43
|
executables:
|
@@ -49,7 +49,6 @@ files:
|
|
49
49
|
- LICENSE
|
50
50
|
- README.md
|
51
51
|
- bin/cstock
|
52
|
-
- cstock-0.1.0.gem
|
53
52
|
- cstock.gemspec
|
54
53
|
- lib/cstock.rb
|
55
54
|
- lib/cstock/stock.rb
|
data/cstock-0.1.0.gem
DELETED
Binary file
|