Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Got security quote import working okay

  • Loading branch information...
commit baeb5d85b0625315913c8a682e583e1fe6ef9545 1 parent 1cd213a
@brymck authored
View
19 ext/rupee/options.c
@@ -139,15 +139,18 @@ static VALUE rupee_black76(VALUE self, VALUE rcall_put_flag, VALUE rF, VALUE rX,
void init_options()
{
- /* Fool RDoc into thinking you're defining a class */
+ VALUE klass, singleton;
+
#if 0
- VALUE cRupee = rb_define_class("Rupee", rb_cObject);
- VALUE sRupee = rb_singleton_class(cRupee);
+ VALUE module = rb_define_module("Rupee");
#endif
- rb_define_singleton_method(cRupee, "black_scholes", rupee_black_scholes, 7);
- rb_define_alias(sRupee, "bs", "black_scholes");
- rb_define_singleton_method(cRupee, "generalized_black_scholes", rupee_generalized_black_scholes, 7);
- rb_define_alias(sRupee, "gbs", "generalized_black_scholes");
- rb_define_singleton_method(cRupee, "black76", rupee_black76, 6);
+ klass = rb_define_class_under(module, "Options", rb_cObject);
+ singleton = rb_singleton_class(klass);
+
+ rb_define_singleton_method(klass, "black_scholes", rupee_black_scholes, 7);
+ rb_define_alias(singleton, "bs", "black_scholes");
+ rb_define_singleton_method(klass, "generalized_black_scholes", rupee_generalized_black_scholes, 7);
+ rb_define_alias(singleton, "gbs", "generalized_black_scholes");
+ rb_define_singleton_method(klass, "black76", rupee_black76, 6);
}
View
5 ext/rupee/rupee.c
@@ -1,12 +1,11 @@
#include "rupee.h"
-VALUE cRupee, sRupee;
+VALUE module;
/* Ruby calls this to load the extension */
void Init_rupee(void)
{
- cRupee = rb_define_class("Rupee", rb_cObject);
- sRupee = rb_singleton_class(cRupee);
+ module = rb_define_module("Rupee");
init_statistics();
init_options();
View
3  ext/rupee/rupee.h
@@ -6,8 +6,7 @@
#include <string.h>
#include <stdbool.h>
-extern VALUE cRupee;
-extern VALUE sRupee;
+extern VALUE module;
#include "statistics.h"
#include "options.h"
View
11 ext/rupee/statistics.c
@@ -46,11 +46,14 @@ static VALUE rupee_cnd(VALUE self, VALUE rz)
void init_statistics()
{
- /* Fool RDoc into thinking you're defining a class */
+ VALUE klass, singleton;
+
#if 0
- VALUE cRupee = rb_define_class("Rupee", rb_cObject);
- VALUE sRupee = rb_singleton_class(cRupee);
+ VALUE module = rb_define_module("Rupee");
#endif
- rb_define_singleton_method(cRupee, "cnd", rupee_cnd, 1);
+ klass = rb_define_class_under(module, "Stat", rb_cObject);
+ singleton = rb_singleton_class(klass);
+
+ rb_define_singleton_method(klass, "cnd", rupee_cnd, 1);
}
View
3  lib/rupee.rb
@@ -2,5 +2,6 @@
require "rupee/version"
# The main Rupee driver
-class Rupee
+module Rupee
+ autoload :Import, "rupee/import"
end
View
40 lib/rupee/import.rb
@@ -0,0 +1,40 @@
+autoload :Net, "net/http"
+autoload :URI, "uri"
+
+module Rupee
+ # The quote and data import functionality in Rupee
+ class Import
+ class << self
+ # Retrieves the current price of a security
+ def quote(url, *options)
+ url = URI.parse(url)
+ res = Net::HTTP.start(url.host, url.port) do |http|
+ http.get url.request_uri
+ end
+ puts res.body
+ end
+
+ # Retrieves the current price of a security from Bloomberg
+ def bloomberg(ticker, *options)
+ quote BLOOMBERG_URL % ticker, options
+ end
+
+ private
+
+ # The URL for Bloomberg's quotes service
+ BLOOMBERG_URL = "http://www.bloomberg.com/apps/quote?ticker=%s"
+
+ # Returns an intepretation of an abbreviated source name
+ def shorten_source(source)
+ case source.downcase.to_sym
+ when :"", :bloomberg, :bberg, :bb, :b
+ :bloomberg
+ when :google, :goog, :g
+ :google
+ when :yahoo!, :yahoo, :yhoo, :y!, :y
+ :yahoo
+ end
+ end
+ end
+ end
+end
View
4 lib/rupee/version.rb
@@ -1,4 +1,4 @@
-class Rupee
+module Rupee
# The current version
- VERSION = "0.0.4"
+ VERSION = "0.0.5"
end
Please sign in to comment.
Something went wrong with that request. Please try again.