ystock 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.markdown +59 -34
  2. data/lib/ystock.rb +7 -5
  3. data/ystock.gemspec +1 -1
  4. metadata +1 -1
data/README.markdown CHANGED
@@ -1,34 +1,59 @@
1
- = Ystock
2
-
3
- Get stock information from Yahoo Finance
4
-
5
- == Install
6
-
7
- gem install ystock
8
-
9
- Add it to your Gemfile
10
-
11
- gem 'ystock'
12
-
13
-
14
- == Usage
15
-
16
- This gem uses Yahoo Finance (yahoo.finance.com) to get stock quotes. Remember the delay is up to 20 mins.
17
-
18
- stock = 'aapl'
19
- Ystock.get_stock(stock)
20
- # Returns an array
21
- ####
22
- # :symbol
23
- # :price
24
- # :change
25
- # :volume
26
-
27
- Get multiple stock information at once. Returns a hash.
28
-
29
- Ystock.find(['aapl', 'goog', 'lcre'])
30
-
31
-
32
- == Build by
33
-
34
- Greg Winn
1
+ # Ystock
2
+
3
+ Get stock information from Yahoo Finance and Google (in beta)
4
+
5
+ ## Install
6
+ Add the following to your Gemfile
7
+ ```ruby
8
+ gem "ystock", "~> 0.3.0"
9
+ ```
10
+ Then run bundle install
11
+
12
+ # Basic Usage
13
+
14
+ ## Single stock
15
+ After you have installed the gem and included it into your Gemfile you can now start to use ystock.
16
+
17
+ 1. In a controller you can do the following:
18
+ ```ruby
19
+ class SomeController < ApplicationController
20
+ def index
21
+ @stock = Ystock.get_stock('appl')
22
+ end
23
+ end
24
+ ```
25
+
26
+ 2. In your view you may display the results:
27
+
28
+ ```html+ruby
29
+ <p>The price of Apple stock is: $<%=@stock[:AAPL][:price]%></p>
30
+ ```
31
+
32
+ #### Available data
33
+ ```
34
+ <%=@stock[:AAPL][:price]%>
35
+ <%=@stock[:AAPL][:change]%>
36
+ <%=@stock[:AAPL][:volume]%>
37
+ ```
38
+
39
+ ## Usage many stocks
40
+ After you have installed the gem and included it into your Gemfile you can now start to use ystock.
41
+
42
+ 1. In a controller you can do the following:
43
+ ```ruby
44
+ class SomeController < ApplicationController
45
+ def index
46
+ @stocks = Ystock.find(["aapl", "goog"])
47
+ end
48
+ end
49
+ ```
50
+
51
+ 2. In your view you may display the results:
52
+
53
+ ```ruby
54
+ @stocks.each do |sym, values|
55
+ # sym -> AAPL
56
+ # values[:price], values[:change], values[:volume]
57
+ puts values[:price]
58
+ end
59
+ ```
data/lib/ystock.rb CHANGED
@@ -94,11 +94,13 @@ module Ystock
94
94
  output = Hash.new
95
95
  results.each_line("\n") do |row|
96
96
  stockdata = row.split(",")
97
- stockdata[3] = stockdata[3].gsub("\r\n", "").gsub('"', '')
98
- output[stockdata[3].to_sym] = {:symbol => stockdata[3],
99
- :price => stockdata[0],
100
- :change => stockdata[1],
101
- :volume => stockdata[2]}
97
+ unless !stockdata[3].nil?
98
+ stockdata[3] = stockdata[3].gsub("\r\n", "").gsub('"', '')
99
+ output[stockdata[3].to_sym] = {:symbol => stockdata[3],
100
+ :price => stockdata[0],
101
+ :change => stockdata[1],
102
+ :volume => stockdata[2]}
103
+ end
102
104
  end
103
105
  return output
104
106
  end
data/ystock.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ystock}
5
- s.version = "0.3.0"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Greg Winn"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ystock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: