tafel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGELOG.txt +8 -0
  2. data/LICENSE.txt +21 -0
  3. data/Makefile +23 -0
  4. data/README.md +7 -0
  5. data/lib/tafel.rb +59 -0
  6. data/tafel.gemspec +35 -0
  7. metadata +68 -0
data/CHANGELOG.txt ADDED
@@ -0,0 +1,8 @@
1
+
2
+ = tafel CHANGELOG.txt
3
+
4
+
5
+ == tafel 0.1.0 released 2016-04-10
6
+
7
+ - initial (empty) release
8
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ Copyright (c) 2016-2016, John Mettraux, jmettraux@gmail.com
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+
data/Makefile ADDED
@@ -0,0 +1,23 @@
1
+
2
+ NAME = \
3
+ $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
4
+ VERSION = \
5
+ $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
6
+
7
+
8
+ gemspec_validate:
9
+ @echo "---"
10
+ ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
11
+ @echo "---"
12
+
13
+ name: gemspec_validate
14
+ @echo "$(NAME) $(VERSION)"
15
+
16
+ build: gemspec_validate
17
+ gem build $(NAME).gemspec
18
+ mkdir -p pkg
19
+ mv $(NAME)-$(VERSION).gem pkg/
20
+
21
+ push: build
22
+ gem push pkg/$(NAME)-$(VERSION).gem
23
+
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+
2
+ # tafel
3
+
4
+ # license
5
+
6
+ MIT, see LICENSE.txt
7
+
data/lib/tafel.rb ADDED
@@ -0,0 +1,59 @@
1
+ #--
2
+ # Copyright (c) 2016-2016, John Mettraux, jmettraux@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Tafel
27
+
28
+ VERSION = '0.1.0'
29
+
30
+ def self.turn(data)
31
+
32
+ data = to_array(data)
33
+
34
+ if data.all? { |row| row.is_a?(Array) }
35
+ data
36
+ elsif data.all? { |row| row.is_a?(Hash) }
37
+ turn_array_of_hashes(data)
38
+ else
39
+ nil
40
+ end
41
+ end
42
+
43
+ protected
44
+
45
+ def self.to_array(data)
46
+
47
+ data
48
+ #return data.values if data.is_a?(Hash)
49
+ #return Array[data]
50
+ end
51
+
52
+ def self.turn_array_of_hashes(data)
53
+
54
+ keys = data.inject([]) { |a, row| a.concat(row.keys) }.uniq
55
+
56
+ [ keys ] + data.collect { |row| keys.collect { |k| row[k] } }
57
+ end
58
+ end
59
+
data/tafel.gemspec ADDED
@@ -0,0 +1,35 @@
1
+
2
+ Gem::Specification.new do |s|
3
+
4
+ s.name = 'tafel'
5
+
6
+ s.version = File.read(
7
+ File.expand_path('../lib/tafel.rb', __FILE__)
8
+ ).match(/ VERSION *= *['"]([^'"]+)/)[1]
9
+
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = [ 'John Mettraux' ]
12
+ s.email = [ 'jmettraux@gmail.com' ]
13
+ s.homepage = 'http://github.com/jmettraux/raabro'
14
+ s.rubyforge_project = 'rufus'
15
+ s.license = 'MIT'
16
+ s.summary = 'something to turn data into an array of arrays'
17
+
18
+ s.description = %{
19
+ Something to turn data (JSON) into an array of arrays (CSV)
20
+ }.strip
21
+
22
+ #s.files = `git ls-files`.split("\n")
23
+ s.files = Dir[
24
+ 'Makefile',
25
+ 'lib/**/*.rb',# 'spec/**/*.rb', 'test/**/*.rb',
26
+ '*.gemspec', '*.txt', '*.rdoc', '*.md'
27
+ ]
28
+
29
+ #s.add_runtime_dependency 'tzinfo'
30
+
31
+ s.add_development_dependency 'rspec', '>= 2.13.0'
32
+
33
+ s.require_path = 'lib'
34
+ end
35
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tafel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Mettraux
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.13.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.13.0
30
+ description: Something to turn data (JSON) into an array of arrays (CSV)
31
+ email:
32
+ - jmettraux@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - Makefile
38
+ - lib/tafel.rb
39
+ - tafel.gemspec
40
+ - CHANGELOG.txt
41
+ - LICENSE.txt
42
+ - README.md
43
+ homepage: http://github.com/jmettraux/raabro
44
+ licenses:
45
+ - MIT
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: rufus
64
+ rubygems_version: 1.8.23.2
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: something to turn data into an array of arrays
68
+ test_files: []