csvhuman 1.0.1 → 1.1.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/Manifest.txt +18 -0
- data/config/attributes.csv +54 -0
- data/config/langs.csv +14 -0
- data/config/tags.csv +45 -0
- data/config/types.csv +7 -0
- data/config/versions.csv +4 -0
- data/lib/csvhuman/base.rb +2 -1
- data/lib/csvhuman/converter.rb +109 -0
- data/lib/csvhuman/doc/helper.rb +108 -0
- data/lib/csvhuman/doc/schema.rb +151 -0
- data/lib/csvhuman/tag.rb +49 -86
- data/lib/csvhuman/version.rb +2 -2
- data/test/data/airports.csv +6 -0
- data/test/data/ebola.csv +76 -0
- data/test/data/hdx/ebola_treatment_centres.csv +94 -0
- data/test/data/hdx/phl_haima_houses_damaged.csv +165 -0
- data/test/data/hdx/zika_cases.csv +303 -0
- data/test/data/unhcr.csv +85 -0
- data/test/test_doc.rb +129 -0
- data/test/test_hdx.rb +28 -0
- data/test/test_misc.rb +28 -0
- data/test/test_type_converters.rb +42 -0
- data/test/test_type_mappings.rb +57 -0
- metadata +20 -2
data/test/test_hdx.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_hdx.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestHdxSamples < MiniTest::Test
|
11
|
+
|
12
|
+
|
13
|
+
def test_ebola
|
14
|
+
recs = CsvHuman.read( "#{CsvHuman.test_data_dir}/hdx/ebola_treatment_centres.csv" )
|
15
|
+
pp recs
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_phl_haima
|
19
|
+
recs = CsvHuman.read( "#{CsvHuman.test_data_dir}/hdx/phl_haima_houses_damaged.csv" )
|
20
|
+
pp recs
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_zika_cases
|
24
|
+
recs = CsvHuman.read( "#{CsvHuman.test_data_dir}/hdx/zika_cases.csv" )
|
25
|
+
pp recs
|
26
|
+
end
|
27
|
+
|
28
|
+
end # class TestHdxSamples
|
data/test/test_misc.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_misc.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestMisc < MiniTest::Test
|
11
|
+
|
12
|
+
|
13
|
+
def test_airports
|
14
|
+
recs = CsvHuman.read( "#{CsvHuman.test_data_dir}/airports.csv" )
|
15
|
+
pp recs
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_unhcr
|
19
|
+
recs = CsvHuman.read( "#{CsvHuman.test_data_dir}/unhcr.csv" )
|
20
|
+
pp recs
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_ebola
|
24
|
+
recs = CsvHuman.read( "#{CsvHuman.test_data_dir}/ebola.csv" )
|
25
|
+
pp recs
|
26
|
+
end
|
27
|
+
|
28
|
+
end # class TestMisc
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_type_converters.rb
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
require 'helper'
|
10
|
+
|
11
|
+
class TestTypeConverters < MiniTest::Test
|
12
|
+
|
13
|
+
def conv_to_i( value )
|
14
|
+
CsvHuman::TYPE_CONVERTERS[Integer].call( value )
|
15
|
+
end
|
16
|
+
|
17
|
+
def conv_to_f( value )
|
18
|
+
CsvHuman::TYPE_CONVERTERS[Float].call( value )
|
19
|
+
end
|
20
|
+
|
21
|
+
def conv_to_date( value )
|
22
|
+
CsvHuman::TYPE_CONVERTERS[Date].call( value )
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def test_integer
|
28
|
+
assert_equal 0, conv_to_i( "0" )
|
29
|
+
assert_equal 2011, conv_to_i( "2011" )
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_float
|
33
|
+
assert_equal 0.0, conv_to_f( "0" )
|
34
|
+
assert_equal 2011.0, conv_to_f( "2011" )
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_date
|
38
|
+
assert_equal Date.new( 2011, 12, 25 ), conv_to_date( "2011-12-25")
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end # class TestTypeConverters
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_type_mappings.rb
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
require 'helper'
|
10
|
+
|
11
|
+
class TestTypeMappings < MiniTest::Test
|
12
|
+
|
13
|
+
def split( value )
|
14
|
+
parts = CsvHuman::Tag.split( value )
|
15
|
+
|
16
|
+
name = parts[0]
|
17
|
+
attributes = parts[1..-1] ## todo/fix: check if nil (make it empty array [] always) - why? why not?
|
18
|
+
|
19
|
+
[name, attributes]
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def conv_guess( value )
|
24
|
+
CsvHuman.guess_type( *split(value) )
|
25
|
+
end
|
26
|
+
|
27
|
+
def conv_default( value )
|
28
|
+
CsvHuman::TYPE_MAPPINGS[:default].call( *split(value) )
|
29
|
+
end
|
30
|
+
|
31
|
+
def conv_none( value )
|
32
|
+
CsvHuman::TYPE_MAPPINGS[:none].call( *split(value) )
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def test_none
|
38
|
+
assert_equal String, conv_none( "#date" )
|
39
|
+
assert_equal String, conv_none( "#date +year" )
|
40
|
+
assert_equal String, conv_none( "#geo +lat" )
|
41
|
+
assert_equal String, conv_none( "#geo +elevation" )
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_guess_and_default
|
45
|
+
assert_equal Date, conv_guess( "#date" )
|
46
|
+
assert_equal Integer, conv_guess( "#date +year" )
|
47
|
+
assert_equal Float, conv_guess( "#geo +lat" )
|
48
|
+
assert_equal Float, conv_guess( "#geo +elevation" )
|
49
|
+
|
50
|
+
assert_equal Date, conv_default( "#date" )
|
51
|
+
assert_equal Integer, conv_default( "#date +year" )
|
52
|
+
assert_equal Float, conv_default( "#geo +lat" )
|
53
|
+
assert_equal Float, conv_default( "#geo +elevation" )
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end # class TestTypeMappings
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csvhuman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.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-11-
|
11
|
+
date: 2018-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csvreader
|
@@ -67,23 +67,41 @@ files:
|
|
67
67
|
- Manifest.txt
|
68
68
|
- README.md
|
69
69
|
- Rakefile
|
70
|
+
- config/attributes.csv
|
71
|
+
- config/langs.csv
|
72
|
+
- config/tags.csv
|
73
|
+
- config/types.csv
|
74
|
+
- config/versions.csv
|
70
75
|
- lib/csvhuman.rb
|
71
76
|
- lib/csvhuman/base.rb
|
72
77
|
- lib/csvhuman/column.rb
|
73
78
|
- lib/csvhuman/converter.rb
|
79
|
+
- lib/csvhuman/doc/helper.rb
|
80
|
+
- lib/csvhuman/doc/schema.rb
|
74
81
|
- lib/csvhuman/reader.rb
|
75
82
|
- lib/csvhuman/tag.rb
|
76
83
|
- lib/csvhuman/version.rb
|
84
|
+
- test/data/airports.csv
|
85
|
+
- test/data/ebola.csv
|
86
|
+
- test/data/hdx/ebola_treatment_centres.csv
|
87
|
+
- test/data/hdx/phl_haima_houses_damaged.csv
|
88
|
+
- test/data/hdx/zika_cases.csv
|
77
89
|
- test/data/sample1.csv
|
78
90
|
- test/data/sample2.csv
|
79
91
|
- test/data/sample3.csv
|
80
92
|
- test/data/sample4.csv
|
81
93
|
- test/data/test.csv
|
94
|
+
- test/data/unhcr.csv
|
82
95
|
- test/helper.rb
|
96
|
+
- test/test_doc.rb
|
97
|
+
- test/test_hdx.rb
|
83
98
|
- test/test_header_converter.rb
|
99
|
+
- test/test_misc.rb
|
84
100
|
- test/test_reader.rb
|
85
101
|
- test/test_samples.rb
|
86
102
|
- test/test_tags.rb
|
103
|
+
- test/test_type_converters.rb
|
104
|
+
- test/test_type_mappings.rb
|
87
105
|
homepage: https://github.com/csvreader/csvhuman
|
88
106
|
licenses:
|
89
107
|
- Public Domain
|