csvpack 0.1.0 → 0.2.0
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 +4 -4
- data/HISTORY.md +4 -4
- data/README.md +354 -354
- data/Rakefile +32 -32
- data/lib/csvpack.rb +52 -52
- data/lib/csvpack/downloader.rb +72 -62
- data/lib/csvpack/pack.rb +47 -7
- data/lib/csvpack/version.rb +22 -22
- data/test/helper.rb +7 -7
- data/test/test_companies.rb +62 -61
- data/test/test_countries.rb +41 -40
- data/test/test_downloader.rb +32 -32
- data/test/test_import.rb +22 -22
- metadata +2 -2
data/test/test_companies.rb
CHANGED
@@ -1,61 +1,62 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_companies.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestCompanies < MiniTest::Test
|
11
|
-
|
12
|
-
def test_s_and_p_500_companies
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
puts "
|
18
|
-
puts "
|
19
|
-
|
20
|
-
|
21
|
-
pp
|
22
|
-
pp
|
23
|
-
|
24
|
-
|
25
|
-
##
|
26
|
-
##
|
27
|
-
|
28
|
-
|
29
|
-
puts
|
30
|
-
|
31
|
-
# database setup 'n' config
|
32
|
-
ActiveRecord::Base.establish_connection( adapter: 'sqlite3',
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
pp company.
|
50
|
-
pp company.
|
51
|
-
pp company.
|
52
|
-
pp company.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_companies.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestCompanies < MiniTest::Test
|
11
|
+
|
12
|
+
def test_s_and_p_500_companies
|
13
|
+
|
14
|
+
pack = CsvPack::Pack.new( './pack/s-and-p-500-companies/datapackage.json' )
|
15
|
+
|
16
|
+
meta = pack.meta
|
17
|
+
puts "name: #{meta.name}"
|
18
|
+
puts "title: #{meta.title}"
|
19
|
+
puts "license: #{meta.license}"
|
20
|
+
|
21
|
+
pp pack.tables
|
22
|
+
pp pack.table[0]['Symbol']
|
23
|
+
pp pack.table[495]['Symbol']
|
24
|
+
|
25
|
+
## pak.table.each do |row|
|
26
|
+
## pp row
|
27
|
+
## end
|
28
|
+
|
29
|
+
puts pack.tables[0].dump_schema
|
30
|
+
|
31
|
+
# database setup 'n' config
|
32
|
+
ActiveRecord::Base.establish_connection( adapter: 'sqlite3',
|
33
|
+
database: ':memory:' )
|
34
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
35
|
+
|
36
|
+
pack.table.up!
|
37
|
+
pack.table.import!
|
38
|
+
|
39
|
+
## pack.tables[0].up!
|
40
|
+
## pack.tables[0].import!
|
41
|
+
|
42
|
+
|
43
|
+
pp pack.table.ar_clazz
|
44
|
+
|
45
|
+
|
46
|
+
company = pack.table.ar_clazz
|
47
|
+
|
48
|
+
puts "Company:"
|
49
|
+
pp company.count
|
50
|
+
pp company.first
|
51
|
+
pp company.find_by!( symbol: 'MMM' )
|
52
|
+
pp company.find_by!( name: '3M Company' )
|
53
|
+
pp company.where( sector: 'Industrials' ).count
|
54
|
+
pp company.where( sector: 'Industrials' ).all
|
55
|
+
|
56
|
+
|
57
|
+
### todo: try a join w/ belongs_to ??
|
58
|
+
|
59
|
+
assert true # if we get here - test success
|
60
|
+
end
|
61
|
+
|
62
|
+
end # class TestCompanies
|
data/test/test_countries.rb
CHANGED
@@ -1,40 +1,41 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_countries.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestCountries < MiniTest::Test
|
11
|
-
|
12
|
-
def test_country_list
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
puts "
|
17
|
-
puts "
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
##
|
23
|
-
##
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
ActiveRecord::Base.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_countries.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestCountries < MiniTest::Test
|
11
|
+
|
12
|
+
def test_country_list
|
13
|
+
pack = CsvPack::Pack.new( './pack/country-list/datapackage.json' )
|
14
|
+
|
15
|
+
meta = pack.meta
|
16
|
+
puts "name: #{meta.name}"
|
17
|
+
puts "title: #{meta.title}"
|
18
|
+
puts "license: #{meta.license}"
|
19
|
+
|
20
|
+
pp pack.tables
|
21
|
+
|
22
|
+
## pak.table.each do |row|
|
23
|
+
## pp row
|
24
|
+
## end
|
25
|
+
|
26
|
+
puts pack.table.dump_schema
|
27
|
+
|
28
|
+
# database setup 'n' config
|
29
|
+
ActiveRecord::Base.establish_connection( adapter: 'sqlite3',
|
30
|
+
database: ':memory:' )
|
31
|
+
ActiveRecord::Base.logger = Logger.new( STDOUT )
|
32
|
+
|
33
|
+
pack.table.up!
|
34
|
+
pack.table.import!
|
35
|
+
|
36
|
+
pp pack.table.ar_clazz
|
37
|
+
|
38
|
+
assert true # if we get here - test success
|
39
|
+
end
|
40
|
+
|
41
|
+
end # class TestCountries
|
data/test/test_downloader.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_downloader.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestDownloader < MiniTest::Test
|
11
|
-
|
12
|
-
def test_download
|
13
|
-
|
14
|
-
names = [
|
15
|
-
'country-list',
|
16
|
-
'country-codes',
|
17
|
-
'language-codes',
|
18
|
-
'cpi', ## Annual Consumer Price Index (CPI)
|
19
|
-
'gdp', ## Country, Regional and World GDP (Gross Domestic Product)
|
20
|
-
's-and-p-500-companies', ## S&P 500 Companies with Financial Information
|
21
|
-
'un-locode', ## UN-LOCODE Codelist - note: incl. country-codes.csv
|
22
|
-
]
|
23
|
-
|
24
|
-
dl =
|
25
|
-
names.each do |name|
|
26
|
-
dl.fetch( name )
|
27
|
-
end
|
28
|
-
|
29
|
-
assert true # if we get here - test success
|
30
|
-
end
|
31
|
-
|
32
|
-
end # class TestDownloader
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_downloader.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestDownloader < MiniTest::Test
|
11
|
+
|
12
|
+
def test_download
|
13
|
+
|
14
|
+
names = [
|
15
|
+
'country-list',
|
16
|
+
'country-codes',
|
17
|
+
'language-codes',
|
18
|
+
'cpi', ## Annual Consumer Price Index (CPI)
|
19
|
+
'gdp', ## Country, Regional and World GDP (Gross Domestic Product)
|
20
|
+
's-and-p-500-companies', ## S&P 500 Companies with Financial Information
|
21
|
+
'un-locode', ## UN-LOCODE Codelist - note: incl. country-codes.csv
|
22
|
+
]
|
23
|
+
|
24
|
+
dl = CsvPack::Downloader.new
|
25
|
+
names.each do |name|
|
26
|
+
dl.fetch( name )
|
27
|
+
end
|
28
|
+
|
29
|
+
assert true # if we get here - test success
|
30
|
+
end
|
31
|
+
|
32
|
+
end # class TestDownloader
|
data/test/test_import.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_import.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestImport < MiniTest::Test
|
11
|
-
|
12
|
-
def test_import
|
13
|
-
|
14
|
-
CsvPack.import(
|
15
|
-
'cpi', ## Annual Consumer Price Index (CPI)
|
16
|
-
'gdp', ## Country, Regional and World GDP (Gross Domestic Product)
|
17
|
-
)
|
18
|
-
|
19
|
-
assert true # if we get here - test success
|
20
|
-
end
|
21
|
-
|
22
|
-
end # class TestImport
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_import.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestImport < MiniTest::Test
|
11
|
+
|
12
|
+
def test_import
|
13
|
+
|
14
|
+
CsvPack.import(
|
15
|
+
'cpi', ## Annual Consumer Price Index (CPI)
|
16
|
+
'gdp', ## Country, Regional and World GDP (Gross Domestic Product)
|
17
|
+
)
|
18
|
+
|
19
|
+
assert true # if we get here - test success
|
20
|
+
end
|
21
|
+
|
22
|
+
end # class TestImport
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csvpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|