gogo_csv 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/gogo_csv/array.rb +18 -0
- data/lib/gogo_csv/matrix.rb +10 -0
- data/lib/gogo_csv/version.rb +1 -1
- data/lib/gogo_csv.rb +14 -15
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e2dc57673003d632a097655c3dc4bc04016d04e
|
4
|
+
data.tar.gz: b899d78da8b8fbf91520a99741fd2dba01fb6de1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c801a1f46951c657e24c0de8af89b7253a361f19d238bec917a4fbf92671ae2e907daa6597336d9da8c6909ed104caa5dc7b6b5c9508a1af6e980c93b89545a1
|
7
|
+
data.tar.gz: 5800b9cec06481cb5f2b20fd7f74fde05160dec634b670a9882666d28bd20992d4de75799c86929a7ec91f98127b7d8ae065925a6696cebd91f05c8a0cfe3956
|
data/README.md
CHANGED
@@ -4,14 +4,14 @@ Extend interface between Array and CSV.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
Install gem as you like.
|
7
|
+
Install gem as you like.
|
8
8
|
|
9
9
|
$ gem install gogo_csv
|
10
10
|
|
11
11
|
|
12
12
|
## Demo
|
13
13
|
```
|
14
|
-
|
14
|
+
require 'gogo_csv'
|
15
15
|
|
16
16
|
arys = read('~/input.csv')
|
17
17
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GogoCsv
|
2
|
+
class ::Array
|
3
|
+
def save!(path)
|
4
|
+
raise 'should be array of array' unless arys?
|
5
|
+
raise 'Should supply file path' unless path ||= $path
|
6
|
+
|
7
|
+
CSV.open(File.expand_path(path), "wb") do |csv|
|
8
|
+
each { |ary| csv << ary }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def arys?
|
15
|
+
all? { |item| item.is_a?(Array) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/gogo_csv/version.rb
CHANGED
data/lib/gogo_csv.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
require "gogo_csv/version"
|
2
|
+
require "gogo_csv/matrix"
|
3
|
+
require "gogo_csv/array"
|
2
4
|
|
3
5
|
module GogoCsv
|
4
6
|
require 'csv'
|
7
|
+
require 'matrix'
|
5
8
|
|
6
|
-
def
|
7
|
-
|
9
|
+
def open(path, format=:matrix)
|
10
|
+
$path = path
|
11
|
+
arys = CSV.read(
|
8
12
|
File.expand_path(path)
|
9
13
|
)
|
10
|
-
end
|
11
|
-
|
12
|
-
class ::Array
|
13
|
-
|
14
|
-
def save!(path)
|
15
|
-
raise 'should be array of array' unless arys?
|
16
|
-
CSV.open(File.expand_path(path), "wb") do |csv|
|
17
|
-
each { |ary| csv << ary }
|
18
|
-
end
|
19
|
-
end
|
20
14
|
|
21
|
-
|
22
|
-
|
15
|
+
case format
|
16
|
+
when :matrix
|
17
|
+
Matrix[*arys]
|
18
|
+
when :arys
|
19
|
+
arys
|
23
20
|
end
|
24
|
-
|
25
21
|
end
|
22
|
+
module_function :open
|
26
23
|
end
|
24
|
+
|
25
|
+
include GogoCsv
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gogo_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,8 @@ files:
|
|
68
68
|
- Rakefile
|
69
69
|
- gogo_csv.gemspec
|
70
70
|
- lib/gogo_csv.rb
|
71
|
+
- lib/gogo_csv/array.rb
|
72
|
+
- lib/gogo_csv/matrix.rb
|
71
73
|
- lib/gogo_csv/version.rb
|
72
74
|
- spec/gogo_csv_spec.rb
|
73
75
|
- spec/spec_helper.rb
|