cstock 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cstock/stock.rb +7 -3
- data/lib/cstock/version.rb +1 -1
- data/spec/cstock_spec.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0396bc11b41a947ddbcef36f1ac9eb01302c8ddd
|
4
|
+
data.tar.gz: 4361d7248eeeb9a096af43045dc893ed454b271d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da8a1fd32a80ba4a716a6a3832e26002e5d5349d89ff171b737c6c6cd526e4011013ce1d5a6cef82ca78615667f7d084c356bb914f093da56ae03b44351000be
|
7
|
+
data.tar.gz: 71810a5d5016a8a7490790930dee3a0ca74d6b74d2ec2f4247c25c53889b24d573de939c340323a65f17ec58f5757064a372db4a63168a8ee37048744cdffc41
|
data/lib/cstock/stock.rb
CHANGED
@@ -22,7 +22,7 @@ module CStock
|
|
22
22
|
@code = stock_code
|
23
23
|
data = self.class.quote(stock_code)[0] if data == nil
|
24
24
|
FIELDS[1..-1].each_with_index do |field, index|
|
25
|
-
instance_variable_set("@#{field}", (data[index].nil? ? nil : data[index]))
|
25
|
+
instance_variable_set("@#{field}", ((data.nil? or data[index].nil?) ? nil : data[index]))
|
26
26
|
end
|
27
27
|
yield self if block_given?
|
28
28
|
end
|
@@ -30,7 +30,7 @@ module CStock
|
|
30
30
|
|
31
31
|
def description
|
32
32
|
FIELDS_ZH.each do |field|
|
33
|
-
puts field + " : " + self.send(field)
|
33
|
+
puts field + " : " + self.send(field).to_s
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -42,7 +42,7 @@ module CStock
|
|
42
42
|
# with the given data to set the stock field values except the fires filed -- code.
|
43
43
|
def set_fields(data)
|
44
44
|
FIELDS[1..-1].each_with_index do |field, index|
|
45
|
-
self.send("#{field}=".to_sym, (data[index].nil? ? nil : data[index]))
|
45
|
+
self.send("#{field}=".to_sym, ((data.nil? or data[index].nil?) ? nil : data[index]))
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -103,5 +103,9 @@ module CStock
|
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
|
+
|
107
|
+
def self.exists?(stock_code)
|
108
|
+
quote(stock_code)[0] ? true : false
|
109
|
+
end
|
106
110
|
end
|
107
111
|
end
|
data/lib/cstock/version.rb
CHANGED
data/spec/cstock_spec.rb
CHANGED
@@ -57,4 +57,24 @@ describe CStock::Stock do
|
|
57
57
|
expect(@s2.name).to eq("大北农")
|
58
58
|
end
|
59
59
|
end
|
60
|
+
|
61
|
+
describe "unexist stock" do
|
62
|
+
it "check stock exist?" do
|
63
|
+
expect(CStock::Stock.exists?("1")).to eq(false)
|
64
|
+
expect(CStock::Stock.exists?("600000")).to eq(true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "init unexist stock" do
|
68
|
+
s = CStock::Stock.new("1")
|
69
|
+
expect(s.name).to eq(nil)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "refresh two stocks: one exist, one not" do
|
73
|
+
s1 = CStock::Stock.new("1")
|
74
|
+
s2 = CStock::Stock.new("600000")
|
75
|
+
CStock::Stock.refresh([s1,s2])
|
76
|
+
expect(s1.name).to eq(nil)
|
77
|
+
expect(s2.name).to eq("浦发银行")
|
78
|
+
end
|
79
|
+
end
|
60
80
|
end
|