bea_as_dataframe 0.1.0 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24b09031564ef29791f0bbd24f900447e00f836123c58499e4cd8aebab02fab9
4
- data.tar.gz: 546d7c3141ffb6b2be5efd78a6764df610c71ac1a3ccbe16649877ef1e985d08
3
+ metadata.gz: cef8074124c70553556b8fa4673e7483c3aab7aaab3c4b81121e1a94f716e99e
4
+ data.tar.gz: 0526b3ba29305027766aa9d401379702de1aa579849baf2fa0ca712ace5adf78
5
5
  SHA512:
6
- metadata.gz: 4560c290948d1fdab0cf0399ce0282d9454237ff33d8c5e818bf5aeee5833818c2a5f80243528242c6b89d0f6aafec02cd6047d6ee63fdbafbeac4f3f28b6d33
7
- data.tar.gz: 47b7ed9162e2245c6b1f22180c70b87fa52105f78b2283aa2ba8f34a14f392df0e60074b272e1f851f66f545ee5021ec015cc2b965df5acb8a1e53dd09e4cc01
6
+ metadata.gz: 0bb3e9e40d873b63d62ee1f1016e33d338ea700de82b1e7816ea5b25841b3b6ab36899108da6c3068b8ff8df5b50f4786eb6fb53cbb1d0d00ca9689a47f69ed3
7
+ data.tar.gz: 15dcba51ec0a2b35e64508fd670b4a2e420c751ad0ebb62695cbd0c35d7c15d6fc23961f027170a610e8cfeb2f1d798a4e60053ea53aa156c40854f7570d5a65
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
+ *.gem
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # BeaAsDataframe
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bea_as_dataframe`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Up to date remote economic data access for ruby, using Polars dataframes.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This package will fetch economic and financial information from the Bureau of Economic Analysis, and return the results as a Polars Dataframe. For some operations, you may need an API key that can be fetched from the BEA website at https://apps.bea.gov/API/signup/ .
6
6
 
7
7
  ## Installation
8
8
 
@@ -20,9 +20,21 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install bea_as_dataframe
22
22
 
23
- ## Usage
23
+ ## Configuration
24
24
 
25
- TODO: Write usage instructions here
25
+ Some data sources will require the specification of an API key. These keys should be provided as part of a configuration file, e.g., config/bea_as_dataframe.rb
26
+
27
+ Other operations (those in BeaAsDataframe::GdpPerCountySector) will require the specification of a directory for temporarily storing datafiles. See the following initialization snippet to providing that customization.
28
+
29
+ ```ruby
30
+ BeaAsDataframe::Client.configure do |config|
31
+ config.api_key = '1234567890ABCDEF'
32
+ # OR
33
+ config.api_key = File.read(File.join('','home', 'user', '.bea_api_key.txt'))
34
+
35
+ config.tmp_dir = File.join('', 'tmp')
36
+ end
37
+ ```
26
38
 
27
39
  ## Development
28
40
 
@@ -2,6 +2,7 @@ require 'polars-df'
2
2
  require 'httparty'
3
3
  require 'csv'
4
4
  require 'zip'
5
+ require 'tempfile'
5
6
 
6
7
  class BeaAsDataframe
7
8
  class GdpPerCountySector
@@ -20,16 +21,16 @@ class BeaAsDataframe
20
21
  resp = HTTParty.get(url)
21
22
  exit if resp.code == 404
22
23
 
23
- Tempfile.create(['CAGDP9','.zip'], @tmp_dir, mode: File::RDWR, binmode: true) do |fn|
24
- fn.write resp.parsed_response
25
- fn.rewind
24
+ Tempfile.create(['CAGDP9','.zip'], @tmp_dir, mode: File::RDWR, binmode: true) do |fn_a|
25
+ fn_a.write resp.parsed_response
26
+ fn_a.rewind
26
27
 
27
- Zip::File.open(fn.path) do |z|
28
+ Zip::File.open(fn_a.path) do |z|
28
29
  z.each do |f|
29
30
  next if (f.name =~ /ALL_AREAS/).nil?
30
31
  content = f.get_input_stream.read.gsub(/^\s*/,'')
31
32
 
32
- Tempfile.create(['gdp_per_cnty_sector', '.csv'], @tmp_dir, mode: File::RDWR) do |fn|
33
+ Tempfile.create(['gdp_per_cnty_sector', '.csv'], @tmp_dir, mode: File::RDWR, binmode: true) do |fn|
33
34
  fnp = fn.path
34
35
  fn.write content
35
36
  fn.rewind
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class BeaAsDataframe
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bea_as_dataframe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bill McKinnon