xbrlware-ruby19 1.1.2.19 → 1.1.2.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/xbrlware-ruby19.rb
CHANGED
@@ -18,7 +18,6 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
require 'rubygems'
|
21
|
-
#gem 'xml-simple'#, '= 1.0.12'
|
22
21
|
require 'xmlsimple'
|
23
22
|
|
24
23
|
require 'date'
|
@@ -59,6 +58,9 @@ require 'xbrlware-ruby19/linkbase/calculation_linkbase'
|
|
59
58
|
require 'xbrlware-ruby19/linkbase/definition_linkbase'
|
60
59
|
require 'xbrlware-ruby19/linkbase/presentation_linkbase'
|
61
60
|
|
61
|
+
require 'xbrlware-ruby19/edgar_data_downloader'
|
62
|
+
require 'xbrlware-ruby19/edgar_util'
|
63
|
+
|
62
64
|
require 'logger'
|
63
65
|
require 'benchmark'
|
64
66
|
|
@@ -0,0 +1,126 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: xbrlware@bitstat.com
|
4
|
+
#
|
5
|
+
# Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
module Edgar
|
21
|
+
|
22
|
+
# This class defines method to download XBRL files from SEC's XBRL RSS Feed.
|
23
|
+
# See {report generation xbrlware wiki}[http://code.google.com/p/xbrlware/wiki/ReportGeneration] for how to use this class.
|
24
|
+
class RSSFeedDownloader
|
25
|
+
include FileUtil
|
26
|
+
|
27
|
+
attr_reader :content
|
28
|
+
|
29
|
+
def initialize(sec_edgar_rss_file=nil)
|
30
|
+
sec_edgar_rss_file ||= "http://www.sec.gov/Archives/edgar/usgaap.rss.xml"
|
31
|
+
@content = XmlSimple.xml_in(open(sec_edgar_rss_file).read, {'ForceContent' => true})
|
32
|
+
end
|
33
|
+
|
34
|
+
# Takes limit (how many entities to download), download_to (where to download)
|
35
|
+
# default value for limit is 100
|
36
|
+
# default value for download_to is current_dir + "/edgar_data"
|
37
|
+
def download(limit=100, download_to=File.expand_path(".")+File::SEPARATOR+"edgar_data")
|
38
|
+
items=@content["channel"][0]["item"]
|
39
|
+
items.each_with_index do |item, index|
|
40
|
+
break if index==limit
|
41
|
+
files=get_xbrl_files(item)
|
42
|
+
download_to += File::SEPARATOR unless download_to.end_with?(File::SEPARATOR)
|
43
|
+
data_dir=download_to
|
44
|
+
data_dir=data_dir+File::SEPARATOR+item["xbrlFiling"][0]["cikNumber"][0]["content"]
|
45
|
+
data_dir=data_dir+File::SEPARATOR+item["xbrlFiling"][0]["accessionNumber"][0]["content"]
|
46
|
+
mkdir(data_dir)
|
47
|
+
files.each do |file|
|
48
|
+
file_content=open(file["edgar:url"]).read
|
49
|
+
dump_to_file(data_dir+File::SEPARATOR+file["edgar:file"], file_content)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def print_stat # :nodoc:
|
55
|
+
i_url=""
|
56
|
+
i_size=0
|
57
|
+
title=""
|
58
|
+
items=@content["channel"][0]["item"]
|
59
|
+
items.each do |item|
|
60
|
+
files=get_xbrl_files(item)
|
61
|
+
files.each do |file|
|
62
|
+
if file["type"]=="EX-101.INS" && (i_size==0 || file["size"].to_i < i_size)
|
63
|
+
i_size = file["edgar:size"].to_i
|
64
|
+
i_url = file["edgar:url"]
|
65
|
+
title = item["edgar:title"]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
puts ""
|
70
|
+
puts " Smallest Instance File " + i_url
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
# Gets url that end with xml and xsd
|
75
|
+
def get_xbrl_files(item)
|
76
|
+
xbrl_files=item["xbrlFiling"][0]["xbrlFiles"][0]["xbrlFile"]
|
77
|
+
return xbrl_files.select {|e| e["edgar:url"].end_with?("xml") || e["edgar:url"].end_with?("xsd")}
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
# This class defines method to download XBRL files from SEC's EDGAR filling url.
|
83
|
+
# See {report generation xbrlware wiki}[http://code.google.com/p/xbrlware/wiki/ReportGeneration] for how to use this class.
|
84
|
+
class HTMLFeedDownloader
|
85
|
+
include REXML::StreamListener
|
86
|
+
include FileUtil
|
87
|
+
|
88
|
+
attr_reader :links
|
89
|
+
|
90
|
+
# Takes url and download_to (where to download)
|
91
|
+
# default value for download_to is current_dir
|
92
|
+
def download(url, download_to=File.expand_path(".")+File::SEPARATOR)
|
93
|
+
$LOG.info " Starting download of fillings from SEC url ["+url+"]"
|
94
|
+
files=[]
|
95
|
+
content = open(url).read
|
96
|
+
@links = Set.new
|
97
|
+
uri=URI(url)
|
98
|
+
@base_path=""
|
99
|
+
@base_path=(uri.scheme+"://"+uri.host+((uri.port==80 && "") || ":"+uri.port.to_s)) unless uri.host.nil?
|
100
|
+
parse(content)
|
101
|
+
download_to += File::SEPARATOR unless download_to.end_with?(File::SEPARATOR)
|
102
|
+
mkdir(download_to)
|
103
|
+
@links.each do |link|
|
104
|
+
file=download_to + link.split("/")[-1]
|
105
|
+
dump_to_file(file, open(link).read)
|
106
|
+
files << file
|
107
|
+
end unless uri.host.nil?
|
108
|
+
files
|
109
|
+
end
|
110
|
+
|
111
|
+
# Callback method for notifying start of xml elements by REXML stream parser.
|
112
|
+
def tag_start(name, attrs) # :nodoc:
|
113
|
+
if "a"==name
|
114
|
+
href=attrs["href"]
|
115
|
+
@links << @base_path + href if href.end_with?("xml") || href.end_with?("xsd")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
def parse(text)
|
121
|
+
REXML::Document.parse_stream(text, self)
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#
|
3
|
+
# Author:: xbrlware@bitstat.com
|
4
|
+
#
|
5
|
+
# Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved.
|
6
|
+
#
|
7
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
16
|
+
# implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
#
|
20
|
+
module Edgar
|
21
|
+
module FileUtil # :nodoc:
|
22
|
+
def mkdir(dir)
|
23
|
+
File.makedirs(dir) unless File.directory?(dir)
|
24
|
+
end
|
25
|
+
|
26
|
+
def dump_to_file(file, content)
|
27
|
+
File.open(file, 'w') {|f| f.write(content) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xbrlware-ruby19
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.2.19
|
4
|
+
version: 1.1.2.19.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: xml-simple
|
17
|
-
requirement: &
|
17
|
+
requirement: &73643820 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *73643820
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bigdecimal
|
28
|
-
requirement: &
|
28
|
+
requirement: &73643610 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *73643610
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: logger
|
39
|
-
requirement: &
|
39
|
+
requirement: &73643400 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *73643400
|
48
48
|
description: Re-packaging of xbrlware for ruby19
|
49
49
|
email:
|
50
50
|
- jim.lindstrom@gmail.com
|
@@ -62,6 +62,8 @@ files:
|
|
62
62
|
- lib/xbrlware-ruby19/constants.rb
|
63
63
|
- lib/xbrlware-ruby19/context.rb
|
64
64
|
- lib/xbrlware-ruby19/date_util.rb
|
65
|
+
- lib/xbrlware-ruby19/edgar_data_downloader.rb
|
66
|
+
- lib/xbrlware-ruby19/edgar_util.rb
|
65
67
|
- lib/xbrlware-ruby19/float_patch.rb
|
66
68
|
- lib/xbrlware-ruby19/hash_util.rb
|
67
69
|
- lib/xbrlware-ruby19/instance.rb
|