Skip to content

Commit

Permalink
Got security quote import working okay
Browse files Browse the repository at this point in the history
  • Loading branch information
brymck committed Sep 26, 2011
1 parent 1cd213a commit baeb5d8
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
19 changes: 11 additions & 8 deletions ext/rupee/options.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ static VALUE rupee_black76(VALUE self, VALUE rcall_put_flag, VALUE rF, VALUE rX,


void init_options() void init_options()
{ {
/* Fool RDoc into thinking you're defining a class */ VALUE klass, singleton;

#if 0 #if 0
VALUE cRupee = rb_define_class("Rupee", rb_cObject); VALUE module = rb_define_module("Rupee");
VALUE sRupee = rb_singleton_class(cRupee);
#endif #endif


rb_define_singleton_method(cRupee, "black_scholes", rupee_black_scholes, 7); klass = rb_define_class_under(module, "Options", rb_cObject);
rb_define_alias(sRupee, "bs", "black_scholes"); singleton = rb_singleton_class(klass);
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(klass, "black_scholes", rupee_black_scholes, 7);
rb_define_singleton_method(cRupee, "black76", rupee_black76, 6); 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);
} }
5 changes: 2 additions & 3 deletions ext/rupee/rupee.c
Original file line number Original file line Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "rupee.h" #include "rupee.h"


VALUE cRupee, sRupee; VALUE module;


/* Ruby calls this to load the extension */ /* Ruby calls this to load the extension */
void Init_rupee(void) void Init_rupee(void)
{ {
cRupee = rb_define_class("Rupee", rb_cObject); module = rb_define_module("Rupee");
sRupee = rb_singleton_class(cRupee);


init_statistics(); init_statistics();
init_options(); init_options();
Expand Down
3 changes: 1 addition & 2 deletions ext/rupee/rupee.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>


extern VALUE cRupee; extern VALUE module;
extern VALUE sRupee;


#include "statistics.h" #include "statistics.h"
#include "options.h" #include "options.h"
Expand Down
11 changes: 7 additions & 4 deletions ext/rupee/statistics.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ static VALUE rupee_cnd(VALUE self, VALUE rz)


void init_statistics() void init_statistics()
{ {
/* Fool RDoc into thinking you're defining a class */ VALUE klass, singleton;

#if 0 #if 0
VALUE cRupee = rb_define_class("Rupee", rb_cObject); VALUE module = rb_define_module("Rupee");
VALUE sRupee = rb_singleton_class(cRupee);
#endif #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);
} }
3 changes: 2 additions & 1 deletion lib/rupee.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
require "rupee/version" require "rupee/version"


# The main Rupee driver # The main Rupee driver
class Rupee module Rupee
autoload :Import, "rupee/import"
end end
40 changes: 40 additions & 0 deletions lib/rupee/import.rb
Original file line number Original file line Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/rupee/version.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
class Rupee module Rupee
# The current version # The current version
VERSION = "0.0.4" VERSION = "0.0.5"
end end

0 comments on commit baeb5d8

Please sign in to comment.