yahoo_finance_lib 0.5 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/yahoo_finance.rb +1 -0
- data/lib/yahoo_finance/company_profile.rb +42 -0
- data/lib/yahoo_finance/stock.rb +5 -2
- data/lib/yahoo_finance/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/yahoo_company_profile_spec.rb +16 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6776bb33144abbb0a5ca933ec3a19a33a1590cb7
|
4
|
+
data.tar.gz: 368acad71871a8c5d97ef2c4ca09d141a0d488dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8765a59969366b1290ef8fa7bb15ff09dc11099c38d8781a425250e3771198bf29baa924834183bba7288b0b54358a5327f2df6b183a23ee7b9764a2eedd235
|
7
|
+
data.tar.gz: 3b3bab9a1fee0b747a048afae4ddd64932cf35c21672c7e88ff952fecfd05c1dc443b4b9efa78b74e8955eee05b7a5a3c3705401e4ca2246940bc2efcb9a76ab
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# YahooFinance library
|
2
2
|
|
3
3
|
YahooFinance lib is a gem that fetches stock quotes, key statistics, company events, and analyst opinion from Yahoo (TM) API and financial HTML pages. The loading of stock quotes uses the excellent nas/yahoo_stock gem. This gem provides a 'unified' attribute based interface, and abstracts the source of the information, i.e. the user only needs to specify an attribute without the need to specify the page source of the attribute. This gem leverages to the highest extend possible the YahooStock (yahoo_stock_nas) gem for all the attributes provided by that gem, and fails over to HTML scraping when the data is unavailable there. Naturally, this has an implication on performance; YahooStock queries bundle 50 stocks in each query, whereas HTML scraping happens one page per stock at a time.
|
4
4
|
|
data/lib/yahoo_finance.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module YahooFinance
|
5
|
+
module CompanyProfile
|
6
|
+
COMPANY_PROFILE_STATS = {
|
7
|
+
:sector => ['Sector:', "Sector classification"],
|
8
|
+
:industry => ['Industry:', 'Industry classification']
|
9
|
+
}
|
10
|
+
def CompanyProfile.key_events_available
|
11
|
+
return YahooFinance::CompanyProfile::COMPANY_PROFILE_STATS.keys;
|
12
|
+
end
|
13
|
+
|
14
|
+
class CompanyProfilePage
|
15
|
+
@symbol
|
16
|
+
|
17
|
+
def initialize symbol
|
18
|
+
@symbol = symbol
|
19
|
+
end
|
20
|
+
|
21
|
+
def fetch
|
22
|
+
url = "http://finance.yahoo.com/q/pr?s=#{@symbol}"
|
23
|
+
open(url) do |stream|
|
24
|
+
@doc = Nokogiri::HTML(stream)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def value_for key_stat
|
29
|
+
if CompanyProfile::key_events_available.include? key_stat
|
30
|
+
begin
|
31
|
+
value = @doc.xpath("//td[text() = \"#{YahooFinance::CompanyProfile::COMPANY_PROFILE_STATS[key_stat][0]}\"]")[0].parent.children[1].text
|
32
|
+
return value
|
33
|
+
rescue
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
else
|
37
|
+
raise StandardError::ArgumentError, "#{key_stat.to_s} not implemented"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/yahoo_finance/stock.rb
CHANGED
@@ -3,6 +3,7 @@ require 'yahoo_stock'
|
|
3
3
|
require 'yahoo_finance/key_statistics'
|
4
4
|
require 'yahoo_finance/company_events'
|
5
5
|
require 'yahoo_finance/analyst_opinion'
|
6
|
+
require 'yahoo_finance/company_profile'
|
6
7
|
|
7
8
|
|
8
9
|
module YahooFinance
|
@@ -10,12 +11,14 @@ module YahooFinance
|
|
10
11
|
:YAHOO_STOCK_FIELDS => YahooStock::Quote.new(:stock_symbols => ['AAPL']).valid_parameters,
|
11
12
|
:KEY_STATISTICS => YahooFinance::KeyStatistics.key_stats_available,
|
12
13
|
:COMPANY_EVENTS => YahooFinance::CompanyEvents.key_events_available,
|
13
|
-
:ANALYST_OPINION => YahooFinance::AnalystOpinion.key_events_available
|
14
|
+
:ANALYST_OPINION => YahooFinance::AnalystOpinion.key_events_available,
|
15
|
+
:COMPANY_PROFILE => YahooFinance::CompanyProfile.key_events_available
|
14
16
|
}
|
15
17
|
DRIVERS = {
|
16
18
|
:KEY_STATISTICS => YahooFinance::KeyStatistics::StatsPage,
|
17
19
|
:COMPANY_EVENTS => YahooFinance::CompanyEvents::CompanyEventsPage,
|
18
|
-
:ANALYST_OPINION => YahooFinance::AnalystOpinion::AnalystOpinionPage
|
20
|
+
:ANALYST_OPINION => YahooFinance::AnalystOpinion::AnalystOpinionPage,
|
21
|
+
:COMPANY_PROFILE => YahooFinance::CompanyProfile::CompanyProfilePage
|
19
22
|
}
|
20
23
|
|
21
24
|
# We are not interested parsing every type of field
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe YahooFinance::CompanyProfile do
|
4
|
+
|
5
|
+
describe "Company Profile" do
|
6
|
+
it "available stats should include things like :sector" do
|
7
|
+
YahooFinance::CompanyProfile.key_events_available.include?(:sector).should == true
|
8
|
+
end
|
9
|
+
it "should fetch a stat like :brokers_count for AAPL and should greater than zero" do
|
10
|
+
pg = YahooFinance::CompanyProfile::CompanyProfilePage.new('AAPL')
|
11
|
+
pg.fetch
|
12
|
+
aapl_sector = pg.value_for :sector
|
13
|
+
aapl_sector.should_not be_nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo_finance_lib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takis Mercouris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nas-yahoo_stock
|
@@ -114,12 +114,14 @@ files:
|
|
114
114
|
- lib/yahoo_finance.rb
|
115
115
|
- lib/yahoo_finance/analyst_opinion.rb
|
116
116
|
- lib/yahoo_finance/company_events.rb
|
117
|
+
- lib/yahoo_finance/company_profile.rb
|
117
118
|
- lib/yahoo_finance/key_statistics.rb
|
118
119
|
- lib/yahoo_finance/stock.rb
|
119
120
|
- lib/yahoo_finance/version.rb
|
120
121
|
- spec/spec_helper.rb
|
121
122
|
- spec/yahoo_analyst_opinion_spec.rb
|
122
123
|
- spec/yahoo_company_events_spec.rb
|
124
|
+
- spec/yahoo_company_profile_spec.rb
|
123
125
|
- spec/yahoo_finance_spec.rb
|
124
126
|
- spec/yahoo_key_stats_spec.rb
|
125
127
|
- yahoo_finance.gemspec
|
@@ -151,5 +153,6 @@ test_files:
|
|
151
153
|
- spec/spec_helper.rb
|
152
154
|
- spec/yahoo_analyst_opinion_spec.rb
|
153
155
|
- spec/yahoo_company_events_spec.rb
|
156
|
+
- spec/yahoo_company_profile_spec.rb
|
154
157
|
- spec/yahoo_finance_spec.rb
|
155
158
|
- spec/yahoo_key_stats_spec.rb
|