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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3b97e81662cbbfe3166ae9eae30417ee4289a18e
4
- data.tar.gz: 71056fd34920000ed4b59ef7c7c76105988e27f4
3
+ metadata.gz: 0396bc11b41a947ddbcef36f1ac9eb01302c8ddd
4
+ data.tar.gz: 4361d7248eeeb9a096af43045dc893ed454b271d
5
5
  SHA512:
6
- metadata.gz: a78156204b08c97f1fdcf6734a2a9db8dba4f37383dcdbe6fcba613bca542fcda8b46831572af708a62375ccb9772f7e38baa5aff54249b1bddeaa8e85a4a2ab
7
- data.tar.gz: 588f4bd31a48b974265b819c9388bcdf7ed2d3212b5a30b6fc506e42618f70f78cb1c225028a4bab838e0ce77e8c86ce5f66db4831bde5d0fb8d4b40ca8fc539
6
+ metadata.gz: da8a1fd32a80ba4a716a6a3832e26002e5d5349d89ff171b737c6c6cd526e4011013ce1d5a6cef82ca78615667f7d084c356bb914f093da56ae03b44351000be
7
+ data.tar.gz: 71810a5d5016a8a7490790930dee3a0ca74d6b74d2ec2f4247c25c53889b24d573de939c340323a65f17ec58f5757064a372db4a63168a8ee37048744cdffc41
@@ -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
@@ -1,4 +1,4 @@
1
1
  # =>CStock::VERSION
2
2
  module CStock
3
- VERSION = '0.4.3'
3
+ VERSION = '0.5.0'
4
4
  end
@@ -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
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.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aston Fu