fech 1.8.1 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +1 -1
- data/lib/fech/filing.rb +26 -26
- data/lib/fech/senate_filing.rb +1 -1
- data/lib/fech/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a65ffc421f1476a1377a5c7301f203d84092810b89d981fa215dff7b79ff8fb5
|
4
|
+
data.tar.gz: cef4ac29dda973b6e4eabaa3fe002c8ff25912681430bf3f6b0fa141b52f1c29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6176c211f7a1639281f7b0f169249f60c8aa3542a8f6d6295f9df9310da6fbd20dcfa230dcad9bc4931833e10db7c319620cc73f39372ccab83440f0cbf76fc2
|
7
|
+
data.tar.gz: 7d1ffa2b9d92c43705b6aa704cd30cff93fefb641a8f0b8c7a9692c78e8a8643aa424a42f143f2644ea03572a1437c29c69467a4190d82ad4b632c3949dd1c18
|
data/Gemfile.lock
CHANGED
data/lib/fech/filing.rb
CHANGED
@@ -3,7 +3,7 @@ require 'open-uri'
|
|
3
3
|
require 'ensure/encoding'
|
4
4
|
|
5
5
|
module Fech
|
6
|
-
|
6
|
+
|
7
7
|
# Fech::Filing downloads an Electronic Filing given its ID, and will search
|
8
8
|
# rows by row type. Using a child Translator object, the data in each row
|
9
9
|
# is automatically mapped at runtime into a labeled Hash. Additional
|
@@ -11,8 +11,8 @@ module Fech
|
|
11
11
|
class Filing
|
12
12
|
# first filing number using the version >=3.00 format
|
13
13
|
# note that there are plenty of <v3 filings after this, so readable? still needs to be checked
|
14
|
-
FIRST_V3_FILING = 11850
|
15
|
-
|
14
|
+
FIRST_V3_FILING = 11850
|
15
|
+
|
16
16
|
attr_accessor :filing_id, :download_dir
|
17
17
|
|
18
18
|
# Create a new Filing object, assign the download directory to system's
|
@@ -44,7 +44,7 @@ module Fech
|
|
44
44
|
end
|
45
45
|
self
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# Access the header (first) line of the filing, containing information
|
49
49
|
# about the filing's version and metadata about the software used to file it.
|
50
50
|
# @return [Hash] a hash that assigns labels to the values of the filing's header row
|
@@ -53,7 +53,7 @@ module Fech
|
|
53
53
|
return parse_row?(row)
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
# Access the summary (second) line of the filing, containing aggregate and
|
58
58
|
# top-level information about the filing.
|
59
59
|
# @return [Hash] a hash that assigns labels to the values of the filing's summary row
|
@@ -63,7 +63,7 @@ module Fech
|
|
63
63
|
return parse_row?(row)
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
# Access all lines of the filing that match a given row type. Will return an
|
68
68
|
# Array of all available lines if called directly, or will yield the mapped
|
69
69
|
# rows one by one if a block is passed.
|
@@ -88,7 +88,7 @@ module Fech
|
|
88
88
|
end
|
89
89
|
block_given? ? nil : data
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
# Decides what to do with a given row. If the row's type matches the desired
|
93
93
|
# type, or if no type was specified, it will run the row through #map.
|
94
94
|
# If :raw was passed true, a flat, unmapped data array will be returned.
|
@@ -119,14 +119,14 @@ module Fech
|
|
119
119
|
def map(row, opts={})
|
120
120
|
data = Fech::Mapped.new(self, row.first)
|
121
121
|
full_row_map = map_for(row.first)
|
122
|
-
|
122
|
+
|
123
123
|
# If specific fields were asked for, return only those
|
124
124
|
if opts[:include]
|
125
125
|
row_map = full_row_map.select { |k| opts[:include].include?(k) }
|
126
126
|
else
|
127
127
|
row_map = full_row_map
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
# Inserts the row into data, performing any specified preprocessing
|
131
131
|
# on individual cells along the way
|
132
132
|
row_map.each_with_index do |field, index|
|
@@ -141,7 +141,7 @@ module Fech
|
|
141
141
|
end
|
142
142
|
data[field] = value
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
# Performs any specified group preprocessing / combinations
|
146
146
|
if translator
|
147
147
|
combinations = translator.get_translations(:row => row.first,
|
@@ -156,14 +156,14 @@ module Fech
|
|
156
156
|
end
|
157
157
|
data
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
# Returns the column names for given row type and the filing's version
|
161
161
|
# in the order they appear in row data.
|
162
162
|
# @param [String, Regexp] row_type representation of the row desired
|
163
163
|
def map_for(row_type)
|
164
164
|
mappings.for_row(row_type)
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
# Returns the column names for given row type and version in the order
|
168
168
|
# they appear in row data.
|
169
169
|
# @param [String, Regexp] row_type representation of the row desired
|
@@ -171,7 +171,7 @@ module Fech
|
|
171
171
|
def self.map_for(row_type, opts={})
|
172
172
|
Fech::Mappings.for_row(row_type, opts)
|
173
173
|
end
|
174
|
-
|
174
|
+
|
175
175
|
# Accessor for @translator. Will return the Translator initialized in
|
176
176
|
# Filing's initializer if built-in translations were passed to Filing's
|
177
177
|
# initializer ({:translate => [:foo, :bar]}).
|
@@ -190,19 +190,19 @@ module Fech
|
|
190
190
|
translator
|
191
191
|
end
|
192
192
|
end
|
193
|
-
|
193
|
+
|
194
194
|
# Whether this filing amends a previous filing or not.
|
195
195
|
def amendment?
|
196
196
|
!amends.nil?
|
197
197
|
end
|
198
|
-
|
198
|
+
|
199
199
|
# Returns the filing ID of the past filing this one amends,
|
200
200
|
# nil if this is a first-draft filing.
|
201
201
|
# :report_id in the HDR line references the amended filing
|
202
202
|
def amends
|
203
203
|
header[:report_id]
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
# Combines an array of keys and values into an Fech::Mapped object,
|
207
207
|
# a type of Hash.
|
208
208
|
# @param [Array] keys the desired keys for the new hash
|
@@ -211,12 +211,12 @@ module Fech
|
|
211
211
|
def hash_zip(keys, values)
|
212
212
|
Fech::Mapped.new(self, values.first).merge(Hash[*keys.zip(values).flatten])
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
# The version of the FEC software used to generate this Filing
|
216
216
|
def filing_version
|
217
217
|
@filing_version ||= parse_filing_version
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
# Pulls out the version number from the header line.
|
221
221
|
# Must parse this line manually, since we don't know the version yet, and
|
222
222
|
# thus the delimiter type is still a mystery.
|
@@ -228,12 +228,12 @@ module Fech
|
|
228
228
|
@csv_parser.parse(first, :col_sep => "\034").flatten[2]
|
229
229
|
end
|
230
230
|
end
|
231
|
-
|
231
|
+
|
232
232
|
# Only FEC format 3.00 + is supported
|
233
233
|
def readable?
|
234
234
|
filing_version.to_i >= 3
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
# Gets or creats the Mappings instance for this filing_version
|
238
238
|
def mappings
|
239
239
|
@mapping ||= Fech::Mappings.new(filing_version)
|
@@ -279,16 +279,16 @@ module Fech
|
|
279
279
|
def fix_f99_contents
|
280
280
|
@customized = true
|
281
281
|
content = file_contents.read
|
282
|
-
|
282
|
+
|
283
283
|
if RUBY_VERSION > "1.9.2"
|
284
284
|
content.encode!('UTF-16', 'UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
|
285
285
|
content.encode!('UTF-8', 'UTF-16')
|
286
286
|
else
|
287
287
|
require 'iconv'
|
288
|
-
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
288
|
+
ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
|
289
289
|
content = ic.iconv(content + ' ')[0..-2] # add valid byte before converting, then remove it
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
regex = /\n\[BEGINTEXT\]\n(.*?)\[ENDTEXT\]\n/mi # some use eg [EndText]
|
293
293
|
match = content.match(regex)
|
294
294
|
if match
|
@@ -311,7 +311,7 @@ module Fech
|
|
311
311
|
end
|
312
312
|
|
313
313
|
def filing_url
|
314
|
-
"
|
314
|
+
"https://docquery.fec.gov/dcdev/posted/#{filing_id}.fec"
|
315
315
|
end
|
316
316
|
|
317
317
|
# Iterates over and yields the Filing's lines
|
@@ -341,11 +341,11 @@ module Fech
|
|
341
341
|
def each_row_with_index(&block)
|
342
342
|
each_row(:with_index => true, &block)
|
343
343
|
end
|
344
|
-
|
344
|
+
|
345
345
|
# @return [String] the delimiter used in the filing's version
|
346
346
|
def delimiter
|
347
347
|
filing_version.to_f < 6 ? "," : "\034"
|
348
348
|
end
|
349
|
-
|
349
|
+
|
350
350
|
end
|
351
351
|
end
|
data/lib/fech/senate_filing.rb
CHANGED
data/lib/fech/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fech
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Strickland
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2019-03
|
15
|
+
date: 2019-06-03 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: fastercsv
|
@@ -252,7 +252,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
252
|
version: '0'
|
253
253
|
requirements: []
|
254
254
|
rubyforge_project: fech
|
255
|
-
rubygems_version: 2.
|
255
|
+
rubygems_version: 2.7.6.2
|
256
256
|
signing_key:
|
257
257
|
specification_version: 4
|
258
258
|
summary: Ruby library for parsing FEC filings.
|