sec 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  == SEC
2
2
 
3
- Retrieve information from the U.S. Securities and Exchange Commission.
3
+ Retrieve {XBRL}[http://xbrl.org/] information from the U.S. Securities and Exchange Commission.
4
4
 
5
5
  == Installation
6
6
 
@@ -18,15 +18,30 @@ Or install it yourself as:
18
18
 
19
19
  == Usage
20
20
 
21
- To retrieve all XBRL filings for March 2012:
21
+ To retrieve an index of all XBRL filings for March 2012:
22
22
 
23
- > response = Sec::MonthlyReader.get_xbrl_index(2012, 3)
23
+ > response = Sec::Reader.get_monthly_index(2012, 3)
24
24
 
25
25
  The response is an RSS document, with each filing in response['channel']['item']
26
26
 
27
- > response = ['rss']['channel']['item'].count
27
+ > response['rss']['channel']['item'].count
28
28
  => 4195
29
29
 
30
+ From there, you can retrieve an individual file:
31
+ > response = Sec::Reader.get_xbrl_file("http://www.sec.gov/Archives/edgar/data/840715/000084071512000011/clro-20111231.xml")
32
+ > puts response.body
33
+ > <?xml version='1.0' encoding='iso-8859-1'?>
34
+ > ...
35
+
36
+ The entries of type "edgar:description"=>"XBRL INSTANCE DOCUMENT" can be parsed by {xbrlware-ruby19}[https://github.com/jimlindstrom/xbrlware-ruby19] for financial facts:
37
+ > require 'xbrlware-ruby19'
38
+
39
+ > ins = Xbrlware.ins(<xbrl_instance_file_path>) # Initialize XBRL instance
40
+ > items = ins.item("ProfitLoss") # Fetch all "ProfitLoss" financial fact
41
+ > items.each do |item|
42
+ > puts item.value # Print value of each "ProfitLoss" item
43
+ > end
44
+
30
45
  == Thanks
31
46
  Many thanks are owed to the following for me to be able to release my first gem:
32
47
  * {Mike Sassak}[http://github.com/msassak]
@@ -1,31 +1,38 @@
1
1
  module Sec
2
- class MonthlyReader
2
+ class Reader
3
3
  class Error < StandardError; end
4
4
 
5
5
  require 'crack'
6
6
 
7
7
  MONTHLY_PATH = %q{/Archives/edgar/monthly/xbrlrss-%{year}-%{month}.xml}
8
8
 
9
- attr_reader :xbrl_hash
9
+ def self.get_monthly_index(year, month)
10
+ reader = Reader.new
11
+ reader.get_monthly_index(year, month)
12
+ end
10
13
 
11
- def self.get_xbrl_index(year, month)
12
- reader = MonthlyReader.new
13
- reader.get_xbrl_index(year, month)
14
+ def self.get_xbrl_file(url)
15
+ reader = Reader.new
16
+ reader.get_xbrl_file(url)
14
17
  end
15
18
 
16
- def get_xbrl_index(year, month)
19
+ def get_monthly_index(year, month)
17
20
  resp = connection.get(monthly_query_uri(year, month))
18
21
  if resp.status == 200
19
22
  # items are in ["rss"]["channel"]
20
- @xbrl_hash = Crack::XML.parse(resp.body)
23
+ Crack::XML.parse(resp.body)
21
24
  else
22
25
  nil
23
26
  end
24
27
  end
25
28
 
29
+ def get_xbrl_file(url)
30
+ resp = connection.get(uri_path(url))
31
+ end
32
+
26
33
  private
27
34
  def connection(attrs={})
28
- Sec::Connection.new
35
+ Connection.new
29
36
  end
30
37
 
31
38
  def prepend_zero(month)
@@ -36,5 +43,9 @@ module Sec
36
43
  def monthly_query_uri(year, month)
37
44
  MONTHLY_PATH % {:year => year, :month => prepend_zero(month)}
38
45
  end
46
+
47
+ def uri_path(url)
48
+ url.gsub(Sec::Connection::SEC_BASE_URL, '')
49
+ end
39
50
  end
40
51
  end
data/lib/sec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sec
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/sec.rb CHANGED
@@ -2,5 +2,5 @@ module Sec
2
2
  end
3
3
 
4
4
  require "sec/connection"
5
- require "sec/monthly_reader"
5
+ require "sec/reader"
6
6
  require "sec/version"
data/sec.gemspec CHANGED
@@ -19,8 +19,10 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_dependency 'crack'
21
21
  gem.add_dependency 'patron'
22
+ gem.add_dependency 'rake'
22
23
 
24
+ gem.add_development_dependency 'pry'
23
25
  gem.add_development_dependency 'rspec'
24
26
  gem.add_development_dependency 'vcr'
25
- gem.add_development_dependency 'webmock'
27
+ gem.add_development_dependency 'webmock', '1.8.11'
26
28
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ module Sec
4
+ describe Reader do
5
+ use_vcr_cassette 'reader'
6
+
7
+ let(:connection) { Sec::Connection.new }
8
+ let(:reader) { Reader.new }
9
+
10
+ describe '.get_monthly_index' do
11
+ let(:response) { reader.get_monthly_index(2012, 1) }
12
+
13
+ it 'returns a hash' do
14
+ expect(response).to be_kind_of(Hash)
15
+ end
16
+
17
+ it 'has a top level rss key' do
18
+ expect(response.keys).to eq(['rss'])
19
+ end
20
+ end
21
+
22
+ describe '.get_xbrl_file' do
23
+ url = "http://www.sec.gov/Archives/edgar/data/840715/000084071512000011/clro-20111231_pre.xml"
24
+ let(:response) { reader.get_xbrl_file(url) }
25
+
26
+ it 'should receive a 200 response code' do
27
+ expect(response.status).to eq(200)
28
+ end
29
+
30
+ # multiple file types, we'll test one
31
+ # I want a more consistent return between the two,
32
+ # one of the TODOs as I use this gem more
33
+ it 'should return an XML string' do
34
+ expect(response.body).to match(/xml\sversion/)
35
+ end
36
+ end
37
+ end
38
+ end