ystock 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +59 -34
- data/lib/ystock.rb +7 -5
- data/ystock.gemspec +1 -1
- metadata +1 -1
data/README.markdown
CHANGED
@@ -1,34 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Get stock information from Yahoo Finance
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
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