quandl_babelfish 0.0.10 → 0.0.11

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.
@@ -1,45 +1,45 @@
1
- require 'spec_helper'
2
- include Quandl::Babelfish
3
- describe Helper do
4
-
5
- before(:each) do
6
- @square_table = [
7
- [1,2,3],
8
- [4,5,6],
9
- [7,8,9]
10
- ]
11
- end
12
-
13
- it 'should square an already square table' do
14
- Helper::make_square(@square_table).should == @square_table
15
- end
16
-
17
- it 'should square an empty table' do
18
- Helper::make_square([]).should == []
19
- end
20
-
21
- it 'should square a single cell table' do
22
- Helper::make_square([[1]]).should == [[1]]
23
- end
24
-
25
- it 'should square a single row table' do
26
- Helper::make_square([[1,2,3]]).should == [[1,2,3]]
27
- end
28
-
29
- it 'should square a nil row table' do
30
- Helper::make_square([[], [1,2,3]]).should == [[nil,nil,nil], [1,2,3]]
31
- end
32
-
33
- it 'should square a nil row table at end too' do
34
- Helper::make_square([[1,2,3], []]).should == [[1,2,3], [nil,nil,nil]]
35
- end
36
-
37
- it 'should square a variable row table' do
38
- Helper::make_square([[1], [1,2,3], [1,2]]).should == [[1,nil,nil], [1,2,3], [1,2,nil]]
39
- end
40
-
41
- it 'should square messy table' do
42
- Helper::make_square([[1],[],[1,2,3],[1],[1],[1,2,3,4,5,6]]).should == [[1,nil,nil,nil,nil,nil], [nil,nil,nil,nil,nil,nil], [1,2,3,nil,nil,nil], [1,nil,nil,nil,nil,nil], [1,nil,nil,nil,nil,nil], [1,2,3,4,5,6]]
43
- end
44
-
1
+ require 'spec_helper'
2
+ include Quandl::Babelfish
3
+ describe Helper do
4
+
5
+ before(:each) do
6
+ @square_table = [
7
+ [1,2,3],
8
+ [4,5,6],
9
+ [7,8,9]
10
+ ]
11
+ end
12
+
13
+ it 'should square an already square table' do
14
+ Helper::make_square(@square_table).should == @square_table
15
+ end
16
+
17
+ it 'should square an empty table' do
18
+ Helper::make_square([]).should == []
19
+ end
20
+
21
+ it 'should square a single cell table' do
22
+ Helper::make_square([[1]]).should == [[1]]
23
+ end
24
+
25
+ it 'should square a single row table' do
26
+ Helper::make_square([[1,2,3]]).should == [[1,2,3]]
27
+ end
28
+
29
+ it 'should square a nil row table' do
30
+ Helper::make_square([[], [1,2,3]]).should == [[nil,nil,nil], [1,2,3]]
31
+ end
32
+
33
+ it 'should square a nil row table at end too' do
34
+ Helper::make_square([[1,2,3], []]).should == [[1,2,3], [nil,nil,nil]]
35
+ end
36
+
37
+ it 'should square a variable row table' do
38
+ Helper::make_square([[1], [1,2,3], [1,2]]).should == [[1,nil,nil], [1,2,3], [1,2,nil]]
39
+ end
40
+
41
+ it 'should square messy table' do
42
+ Helper::make_square([[1],[],[1,2,3],[1],[1],[1,2,3,4,5,6]]).should == [[1,nil,nil,nil,nil,nil], [nil,nil,nil,nil,nil,nil], [1,2,3,nil,nil,nil], [1,nil,nil,nil,nil,nil], [1,nil,nil,nil,nil,nil], [1,2,3,4,5,6]]
43
+ end
44
+
45
45
  end
@@ -1,131 +1,131 @@
1
- require 'spec_helper'
2
-
3
- include Quandl::Babelfish
4
- describe NumberMaid do
5
-
6
- it "should handle '1.432,32' i.e. 1432.32 in Canadian format" do
7
- NumberMaid::init(:decimal_mark => ',')
8
- NumberMaid::clean('1.432,32').should == 1432.32
9
- NumberMaid::init({}) #reset settings
10
- end
11
-
12
- it "should remove spaces that act as 000 separators" do
13
- NumberMaid::clean('12 345').should == 12345
14
- end
15
-
16
- it "should accept commas that act as 000 separators" do
17
- NumberMaid::clean('12,345').should == 12345
18
- end
19
-
20
- it "should handle scientific notation" do
21
- NumberMaid::clean('2.1e2').should == 210
22
- NumberMaid::clean('2.1 E 2').should == 210
23
- NumberMaid::clean('2.1 E+2').should == 210
24
- NumberMaid::clean('210 E -2').should == 2.1
25
- NumberMaid::clean('2.1 e +2').should == 210
26
- NumberMaid::clean('2.1*10^2').should == 210
27
- NumberMaid::clean('2.1 X102').should == 210
28
- NumberMaid::clean('sci not: -2.1 * 10 2 Ghz').should == -210
29
- end
30
-
31
- it "should mulitiply number if cell contains million or billion" do
32
- NumberMaid::clean('35 million').should == 35000000
33
- NumberMaid::clean('42 billion').should == 42000000000
34
- end
35
-
36
- it "should handle a plain integer" do
37
- NumberMaid::clean('1').should == 1
38
- end
39
-
40
- it "should handle a plain negative integer" do
41
- NumberMaid::clean('-1').should == -1
42
- NumberMaid::clean('(1)').should == -1
43
- end
44
-
45
- it "should handle a plain float" do
46
- NumberMaid::clean('1.1').should == 1.1
47
- end
48
-
49
- it "should handle a plain negative float" do
50
- NumberMaid::clean('-1.1').should == -1.1
51
- NumberMaid::clean('(1.1)').should == -1.1
52
- end
53
-
54
- it "should ignore extraneous characters" do
55
- NumberMaid::clean('a1.1a').should == 1.1
56
- NumberMaid::clean('And the answer is 1.1').should == 1.1
57
- NumberMaid::clean('1.1 for the win').should == 1.1
58
- NumberMaid::clean('1.1%').should == 1.1
59
- NumberMaid::clean('-1.1%').should == -1.1
60
- NumberMaid::clean('(1.1%)').should == -1.1
61
- NumberMaid::clean('[1.1%]').should == 1.1
62
- NumberMaid::clean('/1.1%/').should == 1.1
63
- NumberMaid::clean('{1.1%}').should == 1.1
64
- NumberMaid::clean('1.1Ghz').should == 1.1
65
- NumberMaid::clean('(1.1Ghz)').should == -1.1
66
- end
67
-
68
- it 'should get nothing' do
69
- NumberMaid::clean('').should be_nil
70
- NumberMaid::clean('super').should be_nil
71
- NumberMaid::clean('This is great. And then she said...').should be_nil
72
- NumberMaid::clean(' ').should be_nil
73
- NumberMaid::clean('.').should be_nil
74
- NumberMaid::clean('*').should be_nil
75
- NumberMaid::clean('(not a number dude)').should be_nil
76
- NumberMaid::clean('(O.OO)').should be_nil
77
- NumberMaid::clean('#!!@#$%.^&*())').should be_nil # The cartoon swear test
78
- end
79
-
80
- it "should handle this stupid one: '(A1) 249.34' " do
81
- NumberMaid::clean('(A1) 234.3').should == 234.3
82
- NumberMaid::clean('234.3{3}').should == 234.3
83
- NumberMaid::clean('234.3[yes]').should == 234.3
84
- NumberMaid::clean('(234.3)').should == -234.3
85
- NumberMaid::clean('est. 32.8').should == 32.8
86
- NumberMaid::clean('(a6) 9,008').should == 9008
87
- end
88
-
89
- it "should handle: '32.4/66.2'" do
90
- NumberMaid::clean('32.4/18.8').should == 32.4
91
- NumberMaid::clean('32.4 / 18.8').should == 32.4
92
- NumberMaid::clean('32.4 to 18.8').should == 32.4
93
- NumberMaid::clean('273.1/281.7').should == 273.1
94
- NumberMaid::clean('1,013/1,026').should == 1013
95
- NumberMaid::clean('1,013/1,026').should == 1013
96
- NumberMaid::clean('~14,508/14,512').should == 14508
97
- end
98
-
99
- it "should convert many numbers" do
100
- numbers = [2011,'2012*[123]',2013,2014]
101
-
102
- numbers = NumberMaid::clean(numbers)
103
- numbers.length.should == 4
104
- numbers[0].should == 2011
105
- numbers[1].should == 2012
106
- numbers[2].should == 2013
107
- numbers[3].should == 2014
108
- end
109
-
110
- it "should leave nil's for invalid cells" do
111
- numbers = [2011,2012,'abcdef',2014]
112
- numbers = NumberMaid::clean(numbers)
113
- numbers.length.should == 4
114
- numbers[0].should == 2011
115
- numbers[1].should == 2012
116
- numbers[2].should be_nil
117
- numbers[3].should == 2014
118
-
119
- end
120
-
121
- it "should handle crazy long decimals" do
122
- numbers = NumberMaid::clean('0.12345678901234567890')
123
- numbers.should == 0.12345678901235
124
- end
125
-
126
- it "should handle pound in front" do
127
- NumberMaid::clean('#N/A').should be_nil
128
- end
129
-
130
-
131
- end
1
+ require 'spec_helper'
2
+
3
+ include Quandl::Babelfish
4
+ describe NumberMaid do
5
+
6
+ it "should handle '1.432,32' i.e. 1432.32 in Canadian format" do
7
+ NumberMaid::init(:decimal_mark => ',')
8
+ NumberMaid::clean('1.432,32').should == 1432.32
9
+ NumberMaid::init({}) #reset settings
10
+ end
11
+
12
+ it "should remove spaces that act as 000 separators" do
13
+ NumberMaid::clean('12 345').should == 12345
14
+ end
15
+
16
+ it "should accept commas that act as 000 separators" do
17
+ NumberMaid::clean('12,345').should == 12345
18
+ end
19
+
20
+ it "should handle scientific notation" do
21
+ NumberMaid::clean('2.1e2').should == 210
22
+ NumberMaid::clean('2.1 E 2').should == 210
23
+ NumberMaid::clean('2.1 E+2').should == 210
24
+ NumberMaid::clean('210 E -2').should == 2.1
25
+ NumberMaid::clean('2.1 e +2').should == 210
26
+ NumberMaid::clean('2.1*10^2').should == 210
27
+ NumberMaid::clean('2.1 X102').should == 210
28
+ NumberMaid::clean('sci not: -2.1 * 10 2 Ghz').should == -210
29
+ end
30
+
31
+ it "should mulitiply number if cell contains million or billion" do
32
+ NumberMaid::clean('35 million').should == 35000000
33
+ NumberMaid::clean('42 billion').should == 42000000000
34
+ end
35
+
36
+ it "should handle a plain integer" do
37
+ NumberMaid::clean('1').should == 1
38
+ end
39
+
40
+ it "should handle a plain negative integer" do
41
+ NumberMaid::clean('-1').should == -1
42
+ NumberMaid::clean('(1)').should == -1
43
+ end
44
+
45
+ it "should handle a plain float" do
46
+ NumberMaid::clean('1.1').should == 1.1
47
+ end
48
+
49
+ it "should handle a plain negative float" do
50
+ NumberMaid::clean('-1.1').should == -1.1
51
+ NumberMaid::clean('(1.1)').should == -1.1
52
+ end
53
+
54
+ it "should ignore extraneous characters" do
55
+ NumberMaid::clean('a1.1a').should == 1.1
56
+ NumberMaid::clean('And the answer is 1.1').should == 1.1
57
+ NumberMaid::clean('1.1 for the win').should == 1.1
58
+ NumberMaid::clean('1.1%').should == 1.1
59
+ NumberMaid::clean('-1.1%').should == -1.1
60
+ NumberMaid::clean('(1.1%)').should == -1.1
61
+ NumberMaid::clean('[1.1%]').should == 1.1
62
+ NumberMaid::clean('/1.1%/').should == 1.1
63
+ NumberMaid::clean('{1.1%}').should == 1.1
64
+ NumberMaid::clean('1.1Ghz').should == 1.1
65
+ NumberMaid::clean('(1.1Ghz)').should == -1.1
66
+ end
67
+
68
+ it 'should get nothing' do
69
+ NumberMaid::clean('').should be_nil
70
+ NumberMaid::clean('super').should be_nil
71
+ NumberMaid::clean('This is great. And then she said...').should be_nil
72
+ NumberMaid::clean(' ').should be_nil
73
+ NumberMaid::clean('.').should be_nil
74
+ NumberMaid::clean('*').should be_nil
75
+ NumberMaid::clean('(not a number dude)').should be_nil
76
+ NumberMaid::clean('(O.OO)').should be_nil
77
+ NumberMaid::clean('#!!@#$%.^&*())').should be_nil # The cartoon swear test
78
+ end
79
+
80
+ it "should handle this stupid one: '(A1) 249.34' " do
81
+ NumberMaid::clean('(A1) 234.3').should == 234.3
82
+ NumberMaid::clean('234.3{3}').should == 234.3
83
+ NumberMaid::clean('234.3[yes]').should == 234.3
84
+ NumberMaid::clean('(234.3)').should == -234.3
85
+ NumberMaid::clean('est. 32.8').should == 32.8
86
+ NumberMaid::clean('(a6) 9,008').should == 9008
87
+ end
88
+
89
+ it "should handle: '32.4/66.2'" do
90
+ NumberMaid::clean('32.4/18.8').should == 32.4
91
+ NumberMaid::clean('32.4 / 18.8').should == 32.4
92
+ NumberMaid::clean('32.4 to 18.8').should == 32.4
93
+ NumberMaid::clean('273.1/281.7').should == 273.1
94
+ NumberMaid::clean('1,013/1,026').should == 1013
95
+ NumberMaid::clean('1,013/1,026').should == 1013
96
+ NumberMaid::clean('~14,508/14,512').should == 14508
97
+ end
98
+
99
+ it "should convert many numbers" do
100
+ numbers = [2011,'2012*[123]',2013,2014]
101
+
102
+ numbers = NumberMaid::clean(numbers)
103
+ numbers.length.should == 4
104
+ numbers[0].should == 2011
105
+ numbers[1].should == 2012
106
+ numbers[2].should == 2013
107
+ numbers[3].should == 2014
108
+ end
109
+
110
+ it "should leave nil's for invalid cells" do
111
+ numbers = [2011,2012,'abcdef',2014]
112
+ numbers = NumberMaid::clean(numbers)
113
+ numbers.length.should == 4
114
+ numbers[0].should == 2011
115
+ numbers[1].should == 2012
116
+ numbers[2].should be_nil
117
+ numbers[3].should == 2014
118
+
119
+ end
120
+
121
+ it "should handle crazy long decimals" do
122
+ numbers = NumberMaid::clean('0.12345678901234567890')
123
+ numbers.should == 0.12345678901235
124
+ end
125
+
126
+ it "should handle pound in front" do
127
+ NumberMaid::clean('#N/A').should be_nil
128
+ end
129
+
130
+
131
+ end
@@ -1,15 +1,15 @@
1
- require 'spec_helper'
2
-
3
- include Quandl
4
- describe Babelfish do
5
-
6
- it 'should run gem' do
7
- input=[[1990,1,2,3],[1991,4,5,6]]
8
- output, headers = Babelfish::clean input
9
- output[0][0].should ==Date.new(1990,12,31)
10
- output[0][1].should ==1
11
- output[1][0].should ==Date.new(1991,12,31)
12
- output[1][3].should ==6
13
- end
14
-
15
- end
1
+ require 'spec_helper'
2
+
3
+ include Quandl
4
+ describe Babelfish do
5
+
6
+ it 'should run gem' do
7
+ input=[[1990,1,2,3],[1991,4,5,6]]
8
+ output, headers = Babelfish::clean input
9
+ output[0][0].should ==Date.new(1990,12,31)
10
+ output[0][1].should ==1
11
+ output[1][0].should ==Date.new(1991,12,31)
12
+ output[1][3].should ==6
13
+ end
14
+
15
+ end
@@ -1,13 +1,13 @@
1
- $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
-
3
- require 'pry'
4
- require "rspec"
5
- require 'quandl/babelfish'
6
-
7
- # require support
8
- Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
9
-
10
- RSpec.configure do |config|
11
- config.treat_symbols_as_metadata_keys_with_true_values = true
12
- config.mock_with :rspec
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+
3
+ require 'pry'
4
+ require "rspec"
5
+ require 'quandl/babelfish'
6
+
7
+ # require support
8
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.mock_with :rspec
13
13
  end
@@ -1,32 +1,32 @@
1
- RSpec::Matchers.define :be_eq_at_index do |index, expected|
2
- match do |actual|
3
- # value should eq expectation
4
- actual_value_with_index(actual, index) == expected
5
- end
6
-
7
- failure_message_for_should do |actual|
8
- "expected that #{actual_value_with_index(actual, index)} would eq #{expected}"
9
- end
10
-
11
- failure_message_for_should_not do |actual|
12
- "expected that #{actual_value_with_index(actual, index)} would eq #{expected}"
13
- end
14
-
15
- description do
16
- "be eq to #{expected} for array at index #{index}"
17
- end
18
-
19
- def actual_value_with_index(actual, index)
20
- # split string index into keys
21
- indexes = index.to_s.split(']').collect{|v| v.gsub('[','') }
22
- # convert indexes to integers if this is an array
23
- indexes = indexes.collect(&:to_i) if actual.is_a?(Array)
24
- # apply indexes to value
25
- value = actual
26
- indexes.each do |i|
27
- value = value.send(:[], i)
28
- end
29
- value
30
- end
31
-
1
+ RSpec::Matchers.define :be_eq_at_index do |index, expected|
2
+ match do |actual|
3
+ # value should eq expectation
4
+ actual_value_with_index(actual, index) == expected
5
+ end
6
+
7
+ failure_message_for_should do |actual|
8
+ "expected that #{actual_value_with_index(actual, index)} would eq #{expected}"
9
+ end
10
+
11
+ failure_message_for_should_not do |actual|
12
+ "expected that #{actual_value_with_index(actual, index)} would eq #{expected}"
13
+ end
14
+
15
+ description do
16
+ "be eq to #{expected} for array at index #{index}"
17
+ end
18
+
19
+ def actual_value_with_index(actual, index)
20
+ # split string index into keys
21
+ indexes = index.to_s.split(']').collect{|v| v.gsub('[','') }
22
+ # convert indexes to integers if this is an array
23
+ indexes = indexes.collect(&:to_i) if actual.is_a?(Array)
24
+ # apply indexes to value
25
+ value = actual
26
+ indexes.each do |i|
27
+ value = value.send(:[], i)
28
+ end
29
+ value
30
+ end
31
+
32
32
  end