rupee 0.1.9 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in gold_rupee.gemspec
3
+ # Specify your gem's dependencies in rupee.gemspec
4
4
  gemspec
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@ Homepage:: http://www.brymck.com
4
4
  Author:: Bryan McKelvey
5
5
  Copyright:: (c) 2011 Bryan McKelvey
6
6
  License:: MIT
7
- Documentation:: http://rdoc.info/github/brymck/rupee/master/frames
7
+ Documentation:: {brymck.herokuapp.com/rupee/}[http://brymck.herokuapp.com/rupee/]
8
8
 
9
9
  /|\
10
10
  / | \
@@ -57,8 +57,8 @@ Fargo using the following (note that you only need to <tt>require</tt> the
57
57
  require "rupee/quote"
58
58
  wfc = Rupee::Quote.new("WFC")
59
59
 
60
- wfc.get :price, :change, :pct_change
61
- #=> {:price=>24.96, :change=>0.17, :pct_change =>0.686}
60
+ wfc.get :price, :change, :pct_chg
61
+ #=> {:price=>24.96, :change=>0.17, :pct_chg =>0.686}
62
62
 
63
63
  wfc.price
64
64
  #=> 24.96
data/Rakefile CHANGED
@@ -2,18 +2,30 @@ require "bundler/gem_tasks"
2
2
  require "rdoc/task"
3
3
  require "sdoc"
4
4
 
5
+ autoload :FileUtils, "fileutils"
6
+
5
7
  Dir["tasks/**/*.rake"].each do |rake|
6
8
  load File.expand_path(rake)
7
9
  end
8
10
 
9
11
  RDoc::Task.new do |rdoc|
10
- rdoc.main = "README.rdoc"
11
- rdoc.rdoc_dir = "doc"
12
+ rdoc.rdoc_dir = "doc/rdoc"
13
+ rdoc.title = "Rupee Documentation"
14
+
15
+ rdoc.options << "-f" << "sdoc" # format with SDoc
16
+ rdoc.options << "-T" << "rails" # use the Rails template
17
+ rdoc.options << "-c" << "utf-8"
18
+ rdoc.options << "-g" # link to GitHub
19
+ rdoc.options << "-m" << "README.rdoc" # use README.rdoc as main file
20
+ rdoc.options << "-v" # verbose output
21
+
12
22
  rdoc.rdoc_files.include "README.rdoc"
13
23
  rdoc.rdoc_files.include "ext/**/*.{c, h, rb}"
14
24
  rdoc.rdoc_files.include "lib/**/*.rb"
15
- rdoc.options << "-f" << "sdoc"
16
- rdoc.options << "-c" << "utf-8"
17
- rdoc.options << "-g"
18
- rdoc.options << "-m" << "README.rdoc"
25
+ end
26
+
27
+ desc "Copies the documentation files to the path specified in the $RUPEE_DOC environment variable"
28
+ task :docs do
29
+ FileUtils.cp_r "doc/rdoc/.", "#{ENV['RUPEE_DOC']}",
30
+ :remove_destination => true
19
31
  end
@@ -125,10 +125,6 @@ std(values, len)
125
125
  *
126
126
  * Returns the standard normal cumulative distribution (has a mean of zero and
127
127
  * a standard deviation of one).
128
- *
129
- * ==== Arguments
130
- *
131
- * * +z+ - The value for which you want the distribution
132
128
  */
133
129
  static VALUE
134
130
  rupee_cnd(self, _z)
@@ -137,6 +133,10 @@ rupee_cnd(self, _z)
137
133
  return rb_float_new(cnd(NUM2DBL(_z)));
138
134
  }
139
135
 
136
+ /* call-seq: correlation(xvalues, yvalues)
137
+ *
138
+ * Returns the correlation of the supplied x- and y-values.
139
+ */
140
140
  static VALUE
141
141
  rupee_corr(self, _xvals, _yvals)
142
142
  VALUE self, _xvals, _yvals;
@@ -150,6 +150,10 @@ rupee_corr(self, _xvals, _yvals)
150
150
  return rb_float_new(corr(xvals, yvals, len));
151
151
  }
152
152
 
153
+ /* call-seq: covariance(xvalues, yvalues)
154
+ *
155
+ * Returns the covariance of the supplied x- and y-values.
156
+ */
153
157
  static VALUE
154
158
  rupee_cov(self, _xvals, _yvals)
155
159
  VALUE self, _xvals, _yvals;
@@ -163,6 +167,10 @@ rupee_cov(self, _xvals, _yvals)
163
167
  return rb_float_new(cov(xvals, yvals, len));
164
168
  }
165
169
 
170
+ /* call-seq: mean(values)
171
+ *
172
+ * Finds the mean of the specified values.
173
+ */
166
174
  static VALUE
167
175
  rupee_mean(self, _values)
168
176
  VALUE self, _values;
@@ -175,6 +183,10 @@ rupee_mean(self, _values)
175
183
  return rb_float_new(mean(values, len));
176
184
  }
177
185
 
186
+ /* call-seq: standard_deviation(values)
187
+ *
188
+ * Finds the standard deviation of the specified values.
189
+ */
178
190
  static VALUE
179
191
  rupee_std(self, _values)
180
192
  VALUE self, _values;
@@ -187,6 +199,10 @@ rupee_std(self, _values)
187
199
  return rb_float_new(std(values, len));
188
200
  }
189
201
 
202
+ /* call-seq: sum(values)
203
+ *
204
+ * Finds the sum of the specified values.
205
+ */
190
206
  static VALUE
191
207
  rupee_sum(self, _values)
192
208
  VALUE self, _values;
@@ -199,6 +215,10 @@ rupee_sum(self, _values)
199
215
  return rb_float_new(sum(values, len));
200
216
  }
201
217
 
218
+ /* call-seq: variance(values)
219
+ *
220
+ * Finds the variance of the specified values.
221
+ */
202
222
  static VALUE
203
223
  rupee_var(self, _values)
204
224
  VALUE self, _values;
@@ -29,21 +29,50 @@ module Rupee
29
29
  # Bloomberg
30
30
  @sources[:bloomberg] = Source.new(:bloomberg,
31
31
  "http://www.bloomberg.com/apps/quote?ticker=%s",
32
- :price => /(?:PRICE|VALUE): <span class="amount">([0-9.,NA-]{1,})/,
33
- :change => /Change<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
34
- :pct_change => /Change<\/td>\n<td class="value[^>]+>[0-9.,NA-]{1,} \(([0-9NA.,-]{1,})\%/,
35
- :date => /"date">(.*?)</,
36
- :time => /"time">(.*?)</,
37
- :bid => /Bid<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
38
- :ask => /Ask<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
39
- :open => /Open<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
40
- :high => /High<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
41
- :low => /Low<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
42
- :volume => /Volume<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
32
+ :price => /(?:PRICE|VALUE): <span class="amount">([0-9.,NA-]{1,})/,
33
+ :change => /Change<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
34
+ :pct_chg => /Change<\/td>\n<td class="value[^>]+>[0-9.,NA-]{1,} \(([0-9NA.,-]{1,})\%/,
35
+ :date => /"date">(.*?)</,
36
+ :time => /"time">(.*?)</,
37
+ :bid => /Bid<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
38
+ :ask => /Ask<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
39
+ :open => /Open<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
40
+ :high => /High<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
41
+ :low => /Low<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
42
+ :volume => /Volume<\/td>\n<td class="value[^>]+>([0-9.,NA-]{1,})/,
43
43
  :mkt_cap => /Market Cap[^<]+<\/td>\n<td class="value">([0-9.,NA-]{1,})/,
44
44
  :p_e => /Price\/Earnings[^<]+<\/td>\n<td class="value">([0-9.,NA-]{1,})/)
45
- @sources[:yahoo] = Source.new(:yahoo, "yahoo.com")
46
- @sources[:google] = Source.new(:google, "google.com")
45
+
46
+ # Yahoo! Finance
47
+ @sources[:yahoo] = Source.new(:yahoo,
48
+ "http://finance.yahoo.com/q?s=%s",
49
+ :price => /(?:<\/a> |"yfnc_tabledata1"><big><b>)<span id="yfs_l[19]0_[^>]+>([0-9,.-]{1,})/,
50
+ :change => /><span id="yfs_c[16]0_.*?(?:\n[\s\w\-]*\n[\s">\(]*?)?([0-9.,-]{1,})/,
51
+ :pct_chg => /yfs_p[24]0_.*?(?:\n[\s\w\-]*\n[\s">\(]*?)?([0-9.,-]{1,})%\)(?:<\/span>|<\/b><\/span><\/td>)/,
52
+ :date => /<span id="yfs_market_time">.*?, (.*?20[0-9]{1,2})/,
53
+ :time => /(?:"time"|"yfnc_tabledata1")><span id="yfs_t[51]0_[^>]+>(.*?)</,
54
+ :bid => /yfs_b00_[^>]+>([0-9,.-]{1,})/,
55
+ :ask => /yfs_a00_[^>]+>([0-9,.-]{1,})/,
56
+ :open => /Open:<\/th><td class="yfnc_tabledata1">([0-9,.-]{1,})/,
57
+ :high => /yfs_h00_[^>]+>([0-9,.-]{1,})/,
58
+ :low => /yfs_g00_[^>]+>([0-9,.-]{1,})/,
59
+ :volume => /yfs_v00_[^>]+>([0-9,.-]{1,})/,
60
+ :mkt_cap => /yfs_j10_[^>]+>([0-9,.-]{1,}[KMBT]?)/)
61
+
62
+ # Google Finance
63
+ @sources[:google] = Source.new(:google,
64
+ "http://www.google.com/ig/api?stock=%s",
65
+ :price => /<last data="([0-9.-]*)"/,
66
+ :change => /<change data="([0-9.-]*)"/,
67
+ :pct_chg => /<perc_change data="([0-9.-]*)"/,
68
+ :date => /<trade_date_utc data="([0-9.-]*)"/,
69
+ :time => /<trade_date_utc data="([0-9.-]*)"/,
70
+ :open => /<open data="([0-9.-]*)"/,
71
+ :high => /<high data="([0-9.-]*)"/,
72
+ :low => /<low data="([0-9.-]*)"/,
73
+ :volume => /<volume data="([0-9.-]*)"/,
74
+ :mkt_cap => /<market_cap data="([0-9.-]*)"/)
75
+
47
76
  @default_source = :bloomberg
48
77
  end
49
78
  end
data/lib/rupee/quote.rb CHANGED
@@ -106,7 +106,7 @@ module Rupee
106
106
  # parse "abc" #=> "abc"
107
107
  def parse(result)
108
108
  begin
109
- Float(result)
109
+ Float(result.gsub /,/, "")
110
110
  rescue
111
111
  result
112
112
  end
@@ -40,8 +40,15 @@ module Rupee
40
40
  # attr_accessor :price
41
41
  # attr_alias :value, :price
42
42
  #
43
- # would add both a <tt>value</tt> and a <tt>value=</tt> that are equivalent
44
- # to their <tt>price</tt> counterparts.
43
+ # would add both a <tt>value</tt> and a <tt>value=</tt> that are
44
+ # equivalent to their <tt>price</tt> counterparts and would modify the
45
+ # <tt>@price</tt> instance variable. On the other hand,
46
+ #
47
+ # attr :price
48
+ # attr_alias :value, :price
49
+ #
50
+ # would only add <tt>value</tt> method that's equivalent to
51
+ # <tt>price</tt>.
45
52
  def attr_alias(new_read, old_read)
46
53
  alias_method(new_read, old_read) if method_defined?(old_read)
47
54
  new_write = "#{new_read}="
data/lib/rupee/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Rupee
2
2
  # The current version
3
- VERSION = "0.1.9"
3
+ VERSION = "0.2.0"
4
4
  end
@@ -27,5 +27,29 @@ describe Quote do
27
27
  @wfc.next_pull.should == orig_pull - freq_change
28
28
  end
29
29
  end
30
+
31
+ describe "specifying Google Finance as the quote service" do
32
+ before :each do
33
+ @goog = Quote.new("GOOG", :source => :google)
34
+ end
35
+
36
+ it "should have around the same price as Bloomberg" do
37
+ bb_price = Quote.new("GOOG").price
38
+ bb_price.should be_a_kind_of Float
39
+ @goog.price.should be_within(0.05).of bb_price
40
+ end
41
+ end
42
+
43
+ describe "specifying Yahoo! Finance as the quote service" do
44
+ before :each do
45
+ @yahoo = Quote.new("YHOO", :source => :yahoo)
46
+ end
47
+
48
+ it "should have around the same price as Bloomberg" do
49
+ bb_price = Quote.new("YHOO").price
50
+ bb_price.should be_a_kind_of Float
51
+ @yahoo.price.should be_within(0.05).of bb_price
52
+ end
53
+ end
30
54
  end
31
55
  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.1.9
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &72675190 !ruby/object:Gem::Requirement
16
+ requirement: &70293110 !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: *72675190
24
+ version_requirements: *70293110
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &72674810 !ruby/object:Gem::Requirement
27
+ requirement: &70292860 !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: *72674810
35
+ version_requirements: *70292860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sdoc
38
- requirement: &72674470 !ruby/object:Gem::Requirement
38
+ requirement: &70292600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0.3'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *72674470
46
+ version_requirements: *70292600
47
47
  description: ! " rupee aims to provide user-friendly tools for
48
48
  use in\n financial gems and applications.\n"
49
49
  email:
@@ -75,11 +75,11 @@ files:
75
75
  - lib/rupee/security.rb
76
76
  - lib/rupee/version.rb
77
77
  - rupee.gemspec
78
- - spec/import/quote_spec.rb
79
78
  - spec/native/bond_spec.rb
80
79
  - spec/native/future_spec.rb
81
80
  - spec/native/option_spec.rb
82
81
  - spec/native/statistics_spec.rb
82
+ - spec/ruby/quote_spec.rb
83
83
  - spec/spec_helper.rb
84
84
  - tasks/benchmark.rake
85
85
  - test_rubies
@@ -109,8 +109,8 @@ signing_key:
109
109
  specification_version: 3
110
110
  summary: Financial tools for Ruby
111
111
  test_files:
112
- - spec/import/quote_spec.rb
113
112
  - spec/native/bond_spec.rb
114
113
  - spec/native/future_spec.rb
115
114
  - spec/native/option_spec.rb
116
115
  - spec/native/statistics_spec.rb
116
+ - spec/ruby/quote_spec.rb