rupee 0.2.9.2 → 0.2.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --require spec_helper
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
2
3
  require "rdoc/task"
3
4
  require "sdoc"
4
5
 
@@ -8,6 +9,8 @@ Dir["tasks/**/*.rake"].each do |rake|
8
9
  load File.expand_path(rake)
9
10
  end
10
11
 
12
+ RSpec::Core::RakeTask.new
13
+
11
14
  RDoc::Task.new do |rdoc|
12
15
  rdoc.rdoc_dir = "doc/rdoc"
13
16
  rdoc.title = "Rupee Documentation"
@@ -74,7 +74,16 @@ module Rupee
74
74
  when Net::HTTPSuccess
75
75
  @source.params.each do |param, regex|
76
76
  if res.body =~ regex
77
- @results[param] = parse($1)
77
+ full_text, match = $&, $1
78
+
79
+ # Special handling for <tt>:change</tt> because quote services
80
+ # insist on using pretty pictures instead of minus signs
81
+ if param == :change
82
+ if (Source::BLOOMBERG || Source::YAHOO) && full_text =~ /down/
83
+ match = "-#{match}"
84
+ end
85
+ end
86
+ @results[param] = parse(match)
78
87
  else
79
88
  @results[param] = nil
80
89
  end
@@ -11,8 +11,8 @@ module Rupee
11
11
  :bid => /Bid:<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/,
12
12
  :ask => /Ask:<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/,
13
13
  :open => /Open:<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/,
14
- :high => /Day's Range:<\/th>\n\s*<td>[0-9.,NA-]{1,} - ([0-9.,NA-]{1,})/,
15
- :low => /Day's Range:<\/th>\n\s*<td>([0-9.,NA-]{1,})/,
14
+ :high => /(?:Day(?:'s)? Range:<\/th>\n\s*<td[^>]*>[0-9.,NA-]+ - |High - Low:<\/th>\n\s*<td[^>]*>)([0-9.,NA-]+)/,
15
+ :low => /(?:Day(?:'s)? Range:<\/th>\n\s*<td[^>]*>|High - Low:<\/th>\n\s*<td[^>]*>[0-9.,NA-]+ - )([0-9.,NA-]+)/,
16
16
  :volume => /Volume:<\/th>\n\s*<td class[^>]+>([0-9.,NA-]{1,})/,
17
17
  :mkt_cap => /Market Cap[^<]+<\/th>\n\s*<td[^>]*">([0-9.,NA-]{1,})/,
18
18
  :p_e => /Current P\/E[^<]+<\/th>\n\s*<td[^>]*>([0-9.,NA-]{1,})/)
@@ -2,9 +2,9 @@ module Rupee
2
2
  class Source
3
3
  YAHOO = Source.new(:yahoo,
4
4
  "http://finance.yahoo.com/q?s=%s",
5
- :price => /yfs_l84_[^>]+>([0-9,.-]+)/,
6
- :change => /yfs_c(?:6[34]|10)_[^>]+>(?:<img[^>]+>)\s*([0-9,.-])+/,
7
- :pct_chg => /yfs_p(?:4[34]|20)_[^>]+>\(([0-9,.-]+)%\)/,
5
+ :price => /yfs_l(?:10|84)_[^>]+>([0-9,.-]+)/,
6
+ :change => /yfs_c(?:6[034]|10)_[^>]+>(?:<img[^>]+>)\s*([0-9,.-]+)/,
7
+ :pct_chg => /yfs_p(?:4[034]|20)_[^>]+>\(([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,})/,
@@ -1,4 +1,4 @@
1
1
  module Rupee
2
2
  # The current version
3
- VERSION = "0.2.9.2"
3
+ VERSION = "0.2.9.3"
4
4
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
3
  require "rupee/version"
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -14,13 +14,9 @@ Gem::Specification.new do |s|
14
14
  financial gems and applications.
15
15
  eos
16
16
 
17
- s.rubyforge_project = "rupee"
18
-
19
17
  s.files = `git ls-files`.split("\n")
20
18
  s.test_files = `git ls-files -- spec/**/*_spec.rb`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
22
- File.basename(f)
23
- end
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
24
20
  s.extensions = "ext/rupee/extconf.rb"
25
21
  s.require_paths = ["lib", "ext"]
26
22
 
@@ -28,6 +24,9 @@ Gem::Specification.new do |s|
28
24
  s.add_development_dependency "rspec", "~> 2.0"
29
25
  s.add_development_dependency "sdoc", "~> 0.3"
30
26
  s.add_development_dependency "autotest"
31
- s.add_development_dependency "autotest-fsevent"
32
- s.add_development_dependency "autotest-growl"
27
+
28
+ if RUBY_PLATFORM =~ /darwin/
29
+ s.add_development_dependency "autotest-fsevent"
30
+ s.add_development_dependency "autotest-growl"
31
+ end
33
32
  end
@@ -1,10 +1,8 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  # Discrete discounting
4
- # new bond price = 100
5
- #Continous discounting
6
- # bond yield to maturity = 0.09
7
- # new bond price = 104.282
2
+ # new bond price = 100
3
+ # Continous discounting
4
+ # bond yield to maturity = 0.09
5
+ # new bond price = 104.282
8
6
 
9
7
  describe Bond do
10
8
  before :each do
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe Future do
4
2
  before :each do
5
3
  @tolerance = 0.001
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe Option do
4
2
  describe "European option valuation" do
5
3
  before :each do
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe Statistics do
4
2
  before :each do
5
3
  @tolerance = 0.0001
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe BusinessDay do
4
2
  before :each do
5
3
  @new_years = Date.new(2012, 1, 1)
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe Calendar do
4
2
  def test_calendar(calendar, holidays)
5
3
  holidays.each do |holiday|
@@ -1,6 +1,4 @@
1
1
  # encoding: utf-8
2
- require File.dirname(__FILE__) + "/../spec_helper"
3
-
4
2
  describe Currency do
5
3
  it "should at least have the dollar, euro, pound and yen" do
6
4
  Currency::USD.should_not be_nil
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe DayCount do
4
2
  before :each do
5
3
  @christmas = Date.new(2011, 12, 25)
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe FixedIncome do
4
2
  it "should be able to instantiate a basic fixed income product" do
5
3
  lambda { FixedIncome.new }.should_not raise_error
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe "Autoloading" do
4
2
  it "should produce no errors when loading all constants two levels deep" do
5
3
  Rupee.constants.each do |c|
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe Quote do
4
2
  # Attempts to run the block and submits a pending message if a socket error
5
3
  # occurs, the most common cause of which is that the user isn't connected to
@@ -44,6 +42,28 @@ describe Quote do
44
42
  @wfc.frequency -= freq_change
45
43
  @wfc.next_pull.should == orig_pull - freq_change
46
44
  end
45
+
46
+ it "should be able to detect negative and positive changes" do
47
+ run_if_connected do
48
+ eurusd = Quote.new("EURUSD:IND").change
49
+ usdeur = Quote.new("USDEUR:IND").change
50
+ eurusd.should be_within(0.01).of -usdeur
51
+ end
52
+ end
53
+ end
54
+
55
+ describe "requesting security types with special treatment in Bloomberg" do
56
+ it "should grab a change for indices" do
57
+ run_if_connected do
58
+ Quote.new("SPX:IND").change.should_not be_nil
59
+ end
60
+ end
61
+
62
+ it "should grab a change for ETFs" do
63
+ run_if_connected do
64
+ Quote.new("DBA").change.should_not be_nil
65
+ end
66
+ end
47
67
  end
48
68
 
49
69
  describe "specifying Google Finance as the quote service" do
@@ -68,7 +88,6 @@ describe Quote do
68
88
  end
69
89
  end
70
90
  end
71
-
72
91
  end
73
92
 
74
93
  describe "specifying Yahoo! Finance as the quote service" do
@@ -93,5 +112,13 @@ describe Quote do
93
112
  end
94
113
  end
95
114
  end
115
+
116
+ it "should be able to detect negative and positive changes" do
117
+ run_if_connected do
118
+ eurusd = Quote.new("EURUSD=X", :source => :yahoo).change
119
+ usdeur = Quote.new("USDEUR=X", :source => :yahoo).change
120
+ eurusd.should be_within(0.01).of -usdeur
121
+ end
122
+ end
96
123
  end
97
124
  end
@@ -1,5 +1,3 @@
1
- require File.dirname(__FILE__) + "/../spec_helper"
2
-
3
1
  describe Source do
4
2
  it "should have a Bloomberg source" do
5
3
  Source.find(:bloomberg).should_not be_nil
@@ -1,3 +1,3 @@
1
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
2
  require "rupee"
3
3
  include Rupee
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.9.2
4
+ version: 0.2.9.3
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: 2012-02-19 00:00:00.000000000 Z
12
+ date: 2012-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70133540477040 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70133540477040
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &70133540476420 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '2.0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70133540476420
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: sdoc
38
- requirement: &70133540475860 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0.3'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70133540475860
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.3'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: autotest
49
- requirement: &70133540475400 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70133540475400
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: autotest-fsevent
60
- requirement: &70133540474860 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70133540474860
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: autotest-growl
71
- requirement: &70133540474260 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,7 +101,12 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70133540474260
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  description: ! " rupee aims to provide user-friendly tools for
81
111
  use in\n financial gems and applications.\n"
82
112
  email:
@@ -174,8 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
204
  - !ruby/object:Gem::Version
175
205
  version: '0'
176
206
  requirements: []
177
- rubyforge_project: rupee
178
- rubygems_version: 1.8.15
207
+ rubyforge_project:
208
+ rubygems_version: 1.8.21
179
209
  signing_key:
180
210
  specification_version: 3
181
211
  summary: Financial tools for Ruby