rupee 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rupee/quote.rb CHANGED
@@ -72,9 +72,9 @@ module Rupee
72
72
  case res
73
73
  when Net::HTTPSuccess
74
74
  @source.params.each do |param, regex|
75
- begin
76
- @results[param] = parse(regex.match(res.body)[1])
77
- rescue
75
+ if res.body =~ regex
76
+ @results[param] = parse($1)
77
+ else
78
78
  @results[param] = nil
79
79
  end
80
80
  end
@@ -146,11 +146,11 @@ module Rupee
146
146
  # parse "15" # => 15
147
147
  # parse "abc" # => "abc"
148
148
  def parse(result)
149
- begin
150
- Float(result.gsub /,/, "")
151
- rescue
152
- result
153
- end
149
+ return 0.0 if result =~ /N\.A\./
150
+
151
+ Float(result.gsub /,/, "")
152
+ rescue
153
+ result
154
154
  end
155
155
 
156
156
  # Scans the values provided for the number with the greatest number of
@@ -4,7 +4,7 @@ module Rupee
4
4
  GOOGLE = Source.new(:google,
5
5
  "http://www.google.com/ig/api?stock=%s",
6
6
  :price => /<last data="([0-9.-]*)"/,
7
- :change => /<change data="([0-9.-]*)"/,
7
+ :change => /<change data="\+?([0-9.-]*)"/,
8
8
  :pct_chg => /<perc_change data="([0-9.-]*)"/,
9
9
  :date => /<trade_date_utc data="([0-9.-]*)"/,
10
10
  :time => /<trade_date_utc data="([0-9.-]*)"/,
@@ -2,17 +2,17 @@ module Rupee
2
2
  class Source
3
3
  YAHOO = Source.new(:yahoo,
4
4
  "http://finance.yahoo.com/q?s=%s",
5
- :price => /(?:<\/a> |"yfnc_tabledata1"><big><b>)<span id="yfs_l[19]0_[^>]+>([0-9,.-]{1,})/,
6
- :change => /><span id="yfs_c[16]0_.*?(?:\n[\s\w\-]*\n[\s">\(]*?)?([0-9.,-]{1,})/,
7
- :pct_chg => /yfs_p[24]0_.*?(?:\n[\s\w\-]*\n[\s">\(]*?)?([0-9.,-]{1,})%\)(?:<\/span>|<\/b><\/span><\/td>)/,
5
+ :price => /yfs_l84_[^>]+>([0-9,.-]+)/,
6
+ :change => /yfs_c6[34]_[^>]+>(?:<img[^>]+>)\s*([0-9,.-])+/,
7
+ :pct_chg => /yfs_p4[34]_[^>]+>\(([0-9,.-]+)%\)/,
8
8
  :date => /<span id="yfs_market_time">.*?, (.*?20[0-9]{1,2})/,
9
9
  :time => /(?:"time"|"yfnc_tabledata1")><span id="yfs_t[51]0_[^>]+>(.*?)</,
10
10
  :bid => /yfs_b00_[^>]+>([0-9,.-]{1,})/,
11
11
  :ask => /yfs_a00_[^>]+>([0-9,.-]{1,})/,
12
12
  :open => /Open:<\/th><td class="yfnc_tabledata1">([0-9,.-]{1,})/,
13
- :high => /yfs_h00_[^>]+>([0-9,.-]{1,})/,
14
- :low => /yfs_g00_[^>]+>([0-9,.-]{1,})/,
15
- :volume => /yfs_v00_[^>]+>([0-9,.-]{1,})/,
13
+ :high => /yfs_h53_[^>]+>([0-9,.-]{1,})/,
14
+ :low => /yfs_g53_[^>]+>([0-9,.-]{1,})/,
15
+ :volume => /yfs_v53_[^>]+>([0-9,.-]{1,})/,
16
16
  :mkt_cap => /yfs_j10_[^>]+>([0-9,.-]{1,}[KMBT]?)/)
17
17
  end
18
18
  end
data/lib/rupee/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Rupee
2
2
  # The current version
3
- VERSION = "0.2.8"
3
+ VERSION = "0.2.9"
4
4
  end
@@ -32,7 +32,7 @@ describe Quote do
32
32
  [:change, :pct_chg].each do |param|
33
33
  it "should have a #{param}" do
34
34
  run_if_connected do
35
- @wfc.price.should be_a_kind_of Float
35
+ @wfc.send(param).should be_a_kind_of Float
36
36
  end
37
37
  end
38
38
  end
@@ -58,6 +58,17 @@ describe Quote do
58
58
  @goog.price.should be_within(10).of bb_price
59
59
  end
60
60
  end
61
+
62
+ [:change, :pct_chg].each do |param|
63
+ it "should have around the same #{param} as Bloomberg" do
64
+ run_if_connected do
65
+ bb_result = Quote.new("GOOG").send(param)
66
+ bb_result.should be_a_kind_of Float
67
+ @goog.send(param).should be_within(10).of bb_result
68
+ end
69
+ end
70
+ end
71
+
61
72
  end
62
73
 
63
74
  describe "specifying Yahoo! Finance as the quote service" do
@@ -72,5 +83,15 @@ describe Quote do
72
83
  @yahoo.price.should be_within(1).of bb_price
73
84
  end
74
85
  end
86
+
87
+ [:change, :pct_chg].each do |param|
88
+ it "should have around the same #{param} as Bloomberg" do
89
+ run_if_connected do
90
+ bb_result = Quote.new("YHOO").send(param)
91
+ bb_result.should be_a_kind_of Float
92
+ @yahoo.send(param).should be_within(10).of bb_result
93
+ end
94
+ end
95
+ end
75
96
  end
76
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rupee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-20 00:00:00.000000000 Z
12
+ date: 2012-02-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70214885187220 !ruby/object:Gem::Requirement
16
+ requirement: &70180983536300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70214885187220
24
+ version_requirements: *70180983536300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70214885201400 !ruby/object:Gem::Requirement
27
+ requirement: &70180983535100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70214885201400
35
+ version_requirements: *70180983535100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sdoc
38
- requirement: &70214885198020 !ruby/object:Gem::Requirement
38
+ requirement: &70180983534340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70214885198020
46
+ version_requirements: *70180983534340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: autotest
49
- requirement: &70214885197200 !ruby/object:Gem::Requirement
49
+ requirement: &70180983533620 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70214885197200
57
+ version_requirements: *70180983533620
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: autotest-fsevent
60
- requirement: &70214885196560 !ruby/object:Gem::Requirement
60
+ requirement: &70180983532920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70214885196560
68
+ version_requirements: *70180983532920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: autotest-growl
71
- requirement: &70214885195960 !ruby/object:Gem::Requirement
71
+ requirement: &70180983531920 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70214885195960
79
+ version_requirements: *70180983531920
80
80
  description: ! " rupee aims to provide user-friendly tools for
81
81
  use in\n financial gems and applications.\n"
82
82
  email: