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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5ad057a2be681b6dab4d0ec39f7f4a8ad5229a8
4
- data.tar.gz: 91dc842521263c9be65bb9669805f23f2fa85056
3
+ metadata.gz: 3e2dc57673003d632a097655c3dc4bc04016d04e
4
+ data.tar.gz: b899d78da8b8fbf91520a99741fd2dba01fb6de1
5
5
  SHA512:
6
- metadata.gz: 188b9637395792348b32ed5a28f2f33958217c877146313c1c1280f6b4c82577367125d6f814b140ac789e9d80ef87bbe95308cbdd26973e6b5d0d0bc86cea67
7
- data.tar.gz: 017c88634e475d537f28453d8c20d8c2f5431a113b4de74a02a98e342b8b3ba9e93d561f78a9d56c8ecab7264c6bc4a338d7838561c549320a52fa5a9fdf9749
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
- include GogoCsv
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
@@ -0,0 +1,10 @@
1
+ module GogoCsv
2
+ class ::Matrix
3
+ def save!(path=nil)
4
+ raise 'Should supply file path' unless path ||= $path
5
+ CSV.open(File.expand_path(path), "wb") do |csv|
6
+ row_vectors.each { |v| csv << v.to_a }
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module GogoCsv
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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 read(path)
7
- CSV.read(
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
- private def arys?
22
- all? { |item| item.is_a?(Array) }
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.1
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-10-04 00:00:00.000000000 Z
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