nas-yahoo_stock 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -64,4 +64,13 @@ Major changes in the public API. Check the README.rdoc file and individual class
64
64
 
65
65
  * 2 changes:
66
66
  * changes README file to add reference for gemcutter
67
- * changes gemspec to use nas-yahoo_stock
67
+ * changes gemspec to use nas-yahoo_stock
68
+
69
+ === 1.0.4 2009-10-23
70
+
71
+ * 2 addition:
72
+ * adds support for xml format
73
+ * adds cucumber features
74
+
75
+ * 1 changes:
76
+ * changes README file to remove git source add for github
data/Manifest.txt CHANGED
@@ -12,6 +12,7 @@ lib/yahoo_stock/quote.rb
12
12
  lib/yahoo_stock/result.rb
13
13
  lib/yahoo_stock/result/array_format.rb
14
14
  lib/yahoo_stock/result/hash_format.rb
15
+ lib/yahoo_stock/result/xml_format.rb
15
16
  lib/yahoo_stock/scrip_symbol.rb
16
17
  lib/yahoo_stock.rb
17
18
  spec/spec_helper.rb
@@ -25,5 +26,12 @@ spec/yahoo_stock/history_spec.rb
25
26
  spec/yahoo_stock/result_spec.rb
26
27
  spec/yahoo_stock/result/array_format_spec.rb
27
28
  spec/yahoo_stock/result/hash_format_spec.rb
29
+ spec/yahoo_stock/result/xml_format_spec.rb
28
30
  spec/yahoo_stock/scrip_symbol_spec.rb
31
+ features/history.feature
32
+ features/quotes.feature
33
+ features/script_symbol.feature
34
+ features/step_definitions/history_steps.rb
35
+ features/step_definitions/quotes_steps.rb
36
+ features/step_definitions/script_symbol_steps.rb
29
37
 
data/README.rdoc CHANGED
@@ -8,13 +8,11 @@ Provides an interface to yahoo finance to get stock related data. For instance,
8
8
 
9
9
  If you don't know the stock / scrip symbol of the company then you can find that out by using the YahooStock::ScripSymbol class. The methods are mentioned in the Usage section below. For instance, YHOO for yahoo, GOOG for google, etc.
10
10
  The kind of parameters to be passed can be found after initializing the
11
- YahooStock::Quote object and passing valid_parameters message, example is given below in the USAGE section.
11
+ YahooStock::Quote object and passing valid_parameters message to the quote object, example is given below in the USAGE section.
12
12
 
13
13
 
14
14
  == INSTALL:
15
15
 
16
- gem sources -a http://gems.github.com
17
-
18
16
  gem sources -a http://gemcutter.org
19
17
 
20
18
  sudo gem install nas-yahoo_stock
@@ -62,6 +60,10 @@ quote.results
62
60
 
63
61
  quote.results(:to_hash).output
64
62
 
63
+ to return xml, use:
64
+
65
+ quote.results(:to_xml).output
66
+
65
67
  to store results in a file, use:
66
68
 
67
69
  quote.results.store('filename')
@@ -82,6 +84,10 @@ symbol.results
82
84
 
83
85
  symbol.results(:to_hash).output
84
86
 
87
+ to return xml, use:
88
+
89
+ quote.results(:to_xml).output
90
+
85
91
  to store results in a file, use:
86
92
 
87
93
  symbol.results.store('filename')
@@ -108,6 +114,10 @@ symbols.store('filename')
108
114
 
109
115
  to return a hash, use:
110
116
 
117
+ to return xml, use:
118
+
119
+ quote.results(:to_xml).output
120
+
111
121
  history.results(:to_hash).output
112
122
 
113
123
  to store results in a file, use:
@@ -0,0 +1,23 @@
1
+ Feature: Find historical stock data for a stock
2
+ As a user
3
+ I want to find historical data for a stock
4
+ So that I can use the historical data
5
+ Scenario: Get historical data
6
+ Given I do not have any historical data for the symbol "msft"
7
+ When I get historical data for "msft"
8
+ Then I should be able to get history results as a comma separated values in a string
9
+
10
+ Scenario: Get results in array format
11
+ Given I have the history results for the symbol "yhoo"
12
+ When I want to get the history results in array format
13
+ Then I should get an array of history values
14
+
15
+ Scenario: Get results in hash format
16
+ Given I have the history results for the symbol "yhoo"
17
+ When I want to get the history results in hash format
18
+ Then I should get an array of hash key values for history
19
+
20
+ Scenario: Get results in xml format
21
+ Given I have the history results for the symbol "yhoo"
22
+ When I want to get the history results in xml format
23
+ Then I should be able to get history result as xml
@@ -0,0 +1,23 @@
1
+ Feature: Get quotes for a stock
2
+ As a user
3
+ I want to get the stock quotes
4
+ So that I can use them in different formats
5
+ Scenario: Get stock quotes
6
+ Given I do not have any quote results
7
+ When I want to get the quotes for the symbol "yhoo"
8
+ Then I should be able to get results as a comma separated values in a string
9
+
10
+ Scenario: Get results in array format
11
+ Given I have the results for the symbol "yhoo"
12
+ When I want to get the results in array format
13
+ Then I should get an array of values
14
+
15
+ Scenario: Get results in hash format
16
+ Given I have the results for the symbol "yhoo"
17
+ When I want to get the results in hash format
18
+ Then I should get an array of hash key values
19
+
20
+ Scenario: Get results in xml format
21
+ Given I have the results for the symbol "yhoo"
22
+ When I want to get the results in xml format
23
+ Then I should be able to get result as xml
@@ -0,0 +1,23 @@
1
+ Feature: Find Script Symbols
2
+ As a user
3
+ I want to find the script symbols for a company
4
+ So that I can use in other classes
5
+ Scenario: Find Scrip Symbols
6
+ Given I know the name of the company "Yahoo"
7
+ When I try to find the scrip symbols for "Yahoo"
8
+ Then I should be able to get scrip symbol results as a comma separated values in a string
9
+
10
+ Scenario: Get symbol results in array format
11
+ Given I have the scrip symbol results for the symbol "yhoo"
12
+ When I want to get the scrip symbol results in array format
13
+ Then I should get an array of values for scrip symbol
14
+
15
+ Scenario: Get symbol results in hash format
16
+ Given I have the scrip symbol results for the symbol "yhoo"
17
+ When I want to get the scrip symbol results in hash format
18
+ Then I should get an array of hash key values for scrip symbol
19
+
20
+ Scenario: Get symbol results in xml format
21
+ Given I have the scrip symbol results for the symbol "yhoo"
22
+ When I want to get the scrip symbol results in xml format
23
+ Then I should be able to get scrip symbol result as xml
@@ -0,0 +1,44 @@
1
+ Given /^I do not have any historical data for the symbol "([^\"]*)"$/ do |scrip_symbol|
2
+ @history = nil
3
+ end
4
+
5
+ When /^I get historical data for "([^\"]*)"$/ do |arg1|
6
+ @history = YahooStock::History.new(:stock_symbol => 'msft',
7
+ :start_date => Date.today-10,
8
+ :end_date => Date.today-2)
9
+ @results = @history.results
10
+ end
11
+
12
+ Then /^I should be able to get history results as a comma separated values in a string$/ do
13
+ @results.output.should =~ /.*,.*/
14
+ end
15
+
16
+ Given /^I have the history results for the symbol "([^\"]*)"$/ do |stock_symbol|
17
+ @history_format = YahooStock::History.new(:stock_symbol => stock_symbol,
18
+ :start_date => Date.today-4,
19
+ :end_date => Date.today-2)
20
+ end
21
+
22
+ When /^I want to get the history results in array format$/ do
23
+ @array_output = @history_format.results(:to_array).output
24
+ end
25
+
26
+ Then /^I should get an array of history values$/ do
27
+ @array_output.should_not be_empty
28
+ end
29
+
30
+ When /^I want to get the history results in hash format$/ do
31
+ @hash_output = @history_format.results(:to_hash).output
32
+ end
33
+
34
+ Then /^I should get an array of hash key values for history$/ do
35
+ @hash_output.first.keys.should_not be_nil
36
+ end
37
+
38
+ When /^I want to get the history results in xml format$/ do
39
+ @xml_output = @history_format.results(:to_xml).output
40
+ end
41
+
42
+ Then /^I should be able to get history result as xml$/ do
43
+ @xml_output.should =~ /^\<xml*/
44
+ end
@@ -0,0 +1,45 @@
1
+ Given /^I do not have any quote results$/ do
2
+ @quote = nil
3
+ end
4
+
5
+ When /^I want to get the quotes for the symbol "([^\"]*)"$/ do |stock_symbol|
6
+ @quote = YahooStock::Quote.new(:stock_symbols => stock_symbol)
7
+ @results = @quote.results
8
+ end
9
+
10
+ Then /^I should be able to get results as a comma separated values in a string$/ do
11
+ @results.output.should =~ /.*,.*/
12
+ end
13
+
14
+ Given /^I have the results for the symbol "([^\"]*)"$/ do |stock_symbol|
15
+ @quote_format = YahooStock::Quote.new(:stock_symbols => stock_symbol)
16
+ end
17
+
18
+ When /^I want to get the results in array format$/ do
19
+ @array_output = @quote_format.results(:to_array).output
20
+ end
21
+
22
+ Then /^I should get an array of values$/ do
23
+ @array_output.should_not be_empty
24
+ end
25
+
26
+ Then /^by default there should only be two values$/ do
27
+ @array_output.size.should eql(2)
28
+ end
29
+
30
+ When /^I want to get the results in hash format$/ do
31
+ @hash_output = @quote_format.results(:to_hash).output
32
+ end
33
+
34
+ Then /^I should get an array of hash key values$/ do
35
+ @hash_output.first.keys.should include(:last_trade_price_only, :last_trade_date)
36
+ end
37
+
38
+ When /^I want to get the results in xml format$/ do
39
+ @xml_output = @quote_format.results(:to_xml).output
40
+ end
41
+
42
+ Then /^I should be able to get result as xml$/ do
43
+ @xml_output.should =~ /^\<xml*/
44
+ end
45
+
@@ -0,0 +1,40 @@
1
+ Given /^I know the name of the company "([^\"]*)"$/ do |company_name|
2
+ @company_name = company_name
3
+ end
4
+
5
+ When /^I try to find the scrip symbols for "([^\"]*)"$/ do |company_name|
6
+ @symbol = YahooStock::ScripSymbol.new(company_name)
7
+ end
8
+
9
+ Then /^I should be able to get scrip symbol results as a comma separated values in a string$/ do
10
+ @symbol.results.output.should =~ /.*,.*/
11
+ end
12
+
13
+ Given /^I have the scrip symbol results for the symbol "([^\"]*)"$/ do |company|
14
+ @symbol_format = YahooStock::ScripSymbol.new(company)
15
+ @results = @symbol_format.results
16
+ end
17
+
18
+ When /^I want to get the scrip symbol results in array format$/ do
19
+ @array_output = @symbol_format.results(:to_array).output
20
+ end
21
+
22
+ Then /^I should get an array of values for scrip symbol$/ do
23
+ @array_output.should_not be_empty
24
+ end
25
+
26
+ When /^I want to get the scrip symbol results in hash format$/ do
27
+ @hash_output = @symbol_format.results(:to_hash).output
28
+ end
29
+
30
+ Then /^I should get an array of hash key values for scrip symbol$/ do
31
+ @hash_output.first.keys.should_not be_nil
32
+ end
33
+
34
+ When /^I want to get the scrip symbol results in xml format$/ do
35
+ @xml_output = @symbol_format.results(:to_xml).output
36
+ end
37
+
38
+ Then /^I should be able to get scrip symbol result as xml$/ do
39
+ @xml_output.should =~ /^\<xml*/
40
+ end
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'builder'
3
+
4
+ module YahooStock
5
+ # == DESCRIPTION:
6
+ # Convert results to xml
7
+ #
8
+ # == USAGE
9
+ # YahooStock::Result::XmlFormat.new("data as string"){[:keys => :values]}.output
10
+ #
11
+ # Mostly will be used as a separate strategy for formatting results to xml
12
+
13
+ class Result::XmlFormat < Result
14
+ def initialize(data, &block)
15
+ @hash_format = YahooStock::Result::HashFormat.new(data){yield}
16
+ @data = @hash_format.output
17
+ super(self)
18
+ end
19
+
20
+ def output
21
+ builder = Builder::XmlMarkup.new(:indent=>2)
22
+ builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
23
+ builder.items do |items|
24
+ @data.each do |data|
25
+ builder.item do |b|
26
+ data.each_pair do |key, value|
27
+ next if key.nil?
28
+ eval("b.#{key}(value)")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ builder
34
+ end
35
+ end
36
+
37
+ end
data/lib/yahoo_stock.rb CHANGED
@@ -13,6 +13,7 @@ require 'yahoo_stock/interface/scrip_symbol.rb'
13
13
  require 'yahoo_stock/result.rb'
14
14
  require 'yahoo_stock/result/array_format.rb'
15
15
  require 'yahoo_stock/result/hash_format.rb'
16
+ require 'yahoo_stock/result/xml_format.rb'
16
17
 
17
18
  module YahooStock
18
19
  VERSION = '1.0.3'
@@ -40,18 +40,6 @@ describe YahooStock::Result::HashFormat do
40
40
  end
41
41
  end
42
42
 
43
- def output
44
- data = []
45
- @data.each do |datum|
46
- row_values = {}
47
- datum.each_with_index do |item, i|
48
- row_values[keys[i]] = item
49
- end
50
- data << row_values
51
- end
52
- data
53
- end
54
-
55
43
  describe "keys" do
56
44
  it "should replace white space characters to underscore in the keys" do
57
45
  hash_format = YahooStock::Result::HashFormat.new(@data){['ke y 1', 'k e y 2']}
@@ -0,0 +1,54 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe YahooStock::Result::XmlFormat do
4
+ before(:each) do
5
+ @data = "26.71,65620100,MSFT"
6
+ @attributes = "price,volume,symbol"
7
+ end
8
+
9
+ describe ".new" do
10
+ before(:each) do
11
+ @hashed_format = stub('YahooStock::Result::HashFormat')
12
+ YahooStock::Result::HashFormat.stub!(:new).and_return(@hashed_format)
13
+ end
14
+
15
+ it "should create the new hash object" do
16
+ @hashed_format.stub!(:output)
17
+ YahooStock::Result::HashFormat.should_receive(:new).with(@data){ @attributes }.and_return(@hashed_format)
18
+ YahooStock::Result::XmlFormat.new(@data){@attributes}
19
+ end
20
+
21
+ it "should get the output of the hashed format" do
22
+ @hashed_format.should_receive(:output)
23
+ YahooStock::Result::XmlFormat.new(@data){@attributes}
24
+ end
25
+ end
26
+
27
+ describe "#output" do
28
+ before(:each) do
29
+ @builder = stub('Builder::XmlMarkup')
30
+ Builder::XmlMarkup.stub!(:new).and_return(@builder)
31
+ @xml_format = YahooStock::Result::XmlFormat.new(@data){[:last_trade_price_only, :volume, :last_trade_date]}
32
+ @builder.stub!(:instruct!)
33
+ @builder.stub!(:items)
34
+ @builder.stub!(:item)
35
+ end
36
+
37
+ it "should initialise the builder xml markup object" do
38
+ Builder::XmlMarkup.should_receive(:new).and_return(@builder)
39
+ @xml_format.output
40
+ end
41
+
42
+ it "should create the instruct for the xml" do
43
+ @builder.should_receive(:instruct!)
44
+ @xml_format.output
45
+ end
46
+
47
+ it "should create the root element called items" do
48
+ @builder.should_receive(:items)
49
+ @xml_format.output
50
+ end
51
+
52
+ end
53
+
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nas-yahoo_stock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nasir Jamal
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-04 00:00:00 +01:00
12
+ date: 2009-10-23 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: builder
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.2
24
+ version:
16
25
  description: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance
17
26
  email: nas35_in@yahoo.com
18
27
  executables: []
@@ -37,6 +46,7 @@ files:
37
46
  - lib/yahoo_stock/result.rb
38
47
  - lib/yahoo_stock/result/array_format.rb
39
48
  - lib/yahoo_stock/result/hash_format.rb
49
+ - lib/yahoo_stock/result/xml_format.rb
40
50
  - lib/yahoo_stock/scrip_symbol.rb
41
51
  has_rdoc: true
42
52
  homepage: http://github.com/nas/yahoo_stock
@@ -64,7 +74,7 @@ requirements: []
64
74
  rubyforge_project:
65
75
  rubygems_version: 1.3.4
66
76
  signing_key:
67
- specification_version: 3
77
+ specification_version: 2
68
78
  summary: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance.
69
79
  test_files:
70
80
  - spec/spec_helper.rb
@@ -78,4 +88,11 @@ test_files:
78
88
  - spec/yahoo_stock/result_spec.rb
79
89
  - spec/yahoo_stock/result/array_format_spec.rb
80
90
  - spec/yahoo_stock/result/hash_format_spec.rb
91
+ - spec/yahoo_stock/result/xml_format_spec.rb
81
92
  - spec/yahoo_stock/scrip_symbol_spec.rb
93
+ - features/history.feature
94
+ - features/quotes.feature
95
+ - features/script_symbol.feature
96
+ - features/step_definitions/history_steps.rb
97
+ - features/step_definitions/quotes_steps.rb
98
+ - features/step_definitions/script_symbol_steps.rb