quandl_babelfish 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5aa7214cd7f3c0541f0aefe31d983622065bea21
4
- data.tar.gz: 442699776fdbd64183d877e962d564ce2c770664
3
+ metadata.gz: f1debf3ff5b2fc7468dc099a86ba4544eb44e771
4
+ data.tar.gz: ec8f27f490e9bd95558097bee0c463de870dd423
5
5
  SHA512:
6
- metadata.gz: 5a577f380ce3771869c553ebb418c82aa5e9dccb1f493e5cfd06f93a3d804c102df3cd6bb38039a5ddc2630d7ed132c4e68fbb6186b60dab0492f73099bd06cf
7
- data.tar.gz: ea13348aa261380045206aacadda5c8ef4915f7ea9c9210c00f17d1c75f41bee90ba243f240da73e0431c8a573e9ab42354fe2f55e91732f464c2beb7d0663d8
6
+ metadata.gz: 8e659bdbcca4591004cb0e5c7c906a6f27cb0d467000d610bfe14740142b3dcef46699e93d6dd056dd671cb4e486bfb52bd18ea6bf7d2cac923d42c003083b53
7
+ data.tar.gz: 7e490b25c6e5c8c7b28b64b918fffc31ae0a5ae9540101eaf108f25bdf5967fc570b2b589eeaea4b87d03cff164394392fd1b1fae09c7579e13fad9ec941fa42
data/Gemfile CHANGED
@@ -1,2 +1,11 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+
4
+
5
+ use_local_gems = ENV['BUNDLE_LOCAL_GEMS'] == "true" && ENV['BUNDLE_LOCAL_DIR']
6
+ local_gem_dir = ENV['BUNDLE_LOCAL_DIR']
7
+
8
+ if use_local_gems
9
+ gem 'quandl_data', path: "#{local_gem_dir}/quandl/data"
10
+ gem 'quandl_operation', path: "#{local_gem_dir}/quandl/operation"
11
+ end
data/UPGRADE.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 0.0.3
2
+
3
+ * Add Quandl::Data as a add_runtime_dependency
4
+ * refactor Babelfish::Data to inherit from Quandl::Data
5
+ * refactor specs
6
+
7
+
1
8
  ## 0.0.1
2
9
 
3
10
  * replace Cleaner.process return clean_array, header with Quandl::Babelfish::Data.new( clean_array, headers: header )
@@ -24,7 +24,7 @@ class Cleaner
24
24
  clean_array << new_row
25
25
  end
26
26
 
27
- return Quandl::Babelfish::Data.new( clean_array, headers: header )
27
+ return clean_array, header
28
28
  end
29
29
  end
30
30
  end
@@ -1,19 +1,34 @@
1
1
  module Quandl
2
2
  module Babelfish
3
3
 
4
- class Data < Array
4
+ class Data < Quandl::Data
5
5
 
6
- def initialize(*args, &block)
7
- # do we have options?
8
- options = args.pop if args && args.last.is_a?(Hash)
9
- # set headers if given
10
- @headers = options[:headers] if options && options.has_key?(:headers) && options[:headers].is_a?(Array)
11
- # onwards and upwards
12
- super(*args, &block)
6
+ def initialize(*args)
7
+ super(*args)
8
+ # clean data on initialize
9
+ self.data_array
13
10
  end
14
11
 
15
- def headers
16
- @headers ||= nil
12
+
13
+ protected
14
+
15
+ def clean(data)
16
+ # skip cleaning if already clean
17
+ return data if data.kind_of?(Array) && cleaned?
18
+ # Quandl::Data is already clean, but to avoid errors extract internal array
19
+ return data.data_array if data.kind_of?(Quandl::Data)
20
+ # Return empty array if given empty string, nil, etc.
21
+ return [] if data.blank?
22
+ # Hash needs conversion to array
23
+ data = Quandl::Data::Format.hash_to_array( data )
24
+ # String needs conversion to array
25
+ data = Quandl::Data::Format.csv_to_array( data )
26
+ # Babelfish cleaner
27
+ data, self.headers = Quandl::Babelfish.clean(data)
28
+ # mark data as clean
29
+ cleaned!
30
+ # return data
31
+ data
17
32
  end
18
33
 
19
34
  end
@@ -1,5 +1,5 @@
1
1
  module Quandl
2
2
  module Babelfish
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -1,5 +1,7 @@
1
1
  require "quandl/babelfish/version"
2
2
 
3
+ require 'quandl/data'
4
+
3
5
  require "quandl/babelfish/data"
4
6
  require "quandl/babelfish/cleaner"
5
7
  require "quandl/babelfish/date_maid"
@@ -15,7 +15,9 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.require_paths = ["lib"]
18
-
18
+
19
+ s.add_runtime_dependency "quandl_data", "~> 1.3"
20
+
19
21
  s.add_development_dependency "rspec", "~> 2.13"
20
22
  s.add_development_dependency "pry"
21
23
  end
@@ -5,7 +5,9 @@ describe Cleaner do
5
5
 
6
6
  let(:input){ [] }
7
7
  let(:output){ Cleaner.process(input) }
8
- subject{ output }
8
+ let(:data){ output[0] }
9
+ let(:headers){ output[1] }
10
+ subject{ data }
9
11
 
10
12
  context "garbage" do
11
13
  let(:input){ [[2456624, 10], [2456625, 20], [2456626, 30]] }
@@ -14,7 +16,7 @@ describe Cleaner do
14
16
 
15
17
  context "headers with whitespace" do
16
18
  let(:input){ [[" Date ", " C1 ", "C2 ", " C4"],[1990,1,2,3],[1991,4,5,6]] }
17
- its(:headers){ should eq ["Date", "C1", "C2", "C4"] }
19
+ it{ headers.should eq ["Date", "C1", "C2", "C4"] }
18
20
  end
19
21
 
20
22
  context "annual" do
@@ -23,7 +25,7 @@ describe Cleaner do
23
25
  it{ should be_eq_at_index '[0][1]', 1 }
24
26
  it{ should be_eq_at_index '[1][0]', Date.new(1991,12,31) }
25
27
  it{ should be_eq_at_index '[1][3]', 6 }
26
- its(:headers){ should be_nil }
28
+ it{ headers.should be_nil }
27
29
  end
28
30
 
29
31
  context "numeric date" do
@@ -32,7 +34,7 @@ describe Cleaner do
32
34
  it{ should be_eq_at_index '[0][1]', 1 }
33
35
  it{ should be_eq_at_index '[0][2]', 2.3 }
34
36
  it{ should be_eq_at_index '[0][3]', nil }
35
- its(:headers){ should be_nil }
37
+ it{ headers.should be_nil }
36
38
  end
37
39
 
38
40
  context "data with headers" do
@@ -41,7 +43,7 @@ describe Cleaner do
41
43
  it{ should be_eq_at_index '[0][1]', 1 }
42
44
  it{ should be_eq_at_index '[0][2]', 2.3 }
43
45
  it{ should be_eq_at_index '[0][3]', nil }
44
- its(:headers){ should eq ['Date','0','0','0'] }
46
+ it{ headers.should eq ['Date','0','0','0'] }
45
47
  end
46
48
 
47
49
  end
@@ -1,33 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Quandl::Babelfish::Data do
4
- let(:data_args){ [] }
5
- subject{ Quandl::Babelfish::Data.new(*data_args) }
6
4
 
7
- its(:to_a){ should eq [] }
8
- its(:headers){ should be_nil }
9
-
10
- context "given Array" do
11
- let(:data_args){ [ [[1,2,3],[4,3,5]] ] }
12
- its(:to_a){ should eq [[1,2,3],[4,3,5]] }
13
- its(:headers){ should be_nil }
14
- end
5
+ let(:csv) { "Date, Column 1, Column 2, C3, C4, C5, C6, C7\n 2012-03-07,,69.75,69.75,69.75,0.0,0.0,0.0\n2012-03-06,69.75,69.75,69.75,69.75,0.0,0.0,0.0\n2012-03-05,69.75,69.75,69.75,69.75,0.0,0.0,0.0\n2012-03-04,69.75,69.75,69.75,69.75,0.0,0.0,0.0\n2012-02-29,,69.75,69.75,69.75,0.0,0.0,0.0\n2012-02-28,69.75,69.75,69.75,69.75,0.0,0.0,0.0\n" }
15
6
 
16
- context "given Array with :headers" do
17
- let(:data_args){ [ [[1,2,3],[4,3,5]], { headers: ['Date', 'C1', 'C2'] } ] }
18
- its(:to_a){ should eq [[1,2,3],[4,3,5]] }
19
- its(:headers){ should eq ['Date', 'C1', 'C2'] }
20
- end
7
+ let(:data){ Quandl::Babelfish::Data.new(csv) }
8
+ subject{ data }
9
+
10
+ let(:expected_data){ [['2012-03-07',nil,69.75,69.75,69.75,0.0,0.0,0.0],['2012-03-06',69.75,69.75,69.75,69.75,0.0,0.0,0.0],['2012-03-05',69.75,69.75,69.75,69.75,0.0,0.0,0.0],['2012-03-04',69.75,69.75,69.75,69.75,0.0,0.0,0.0],['2012-02-29',nil,69.75,69.75,69.75,0.0,0.0,0.0],['2012-02-28',69.75,69.75,69.75,69.75,0.0,0.0,0.0]] }
11
+ let(:expected_headers){ ['Date', 'Column 1', 'Column 2', 'C3', 'C4', 'C5', 'C6', 'C7'] }
12
+
13
+ its(:headers){ should eq expected_headers }
14
+ its('clone.headers'){ should eq expected_headers }
15
+ its('to_jd.headers'){ should eq expected_headers }
16
+
17
+ its(:to_date_str){ should eq expected_data }
21
18
 
22
- context "given junk headers: Float" do
23
- let(:data_args){ [ 2, { headers: 1.2 } ] }
24
- its(:to_a){ should eq [nil,nil] }
25
- its(:headers){ should be_nil }
26
- end
27
- context "given junk headers: String" do
28
- let(:data_args){ [ 2, { headers: '1.2' } ] }
29
- its(:to_a){ should eq [nil,nil] }
30
- its(:headers){ should be_nil }
31
- end
32
-
33
19
  end
@@ -5,7 +5,7 @@ describe Babelfish do
5
5
 
6
6
  it 'should run gem' do
7
7
  input=[[1990,1,2,3],[1991,4,5,6]]
8
- output = Babelfish::clean input
8
+ output, headers = Babelfish::clean input
9
9
  output[0][0].should ==Date.new(1990,12,31)
10
10
  output[0][1].should ==1
11
11
  output[1][0].should ==Date.new(1991,12,31)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quandl_babelfish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergei Ryshkevich
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: quandl_data
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement