lib/gogo_csv.rb in gogo_csv-0.0.1 vs lib/gogo_csv.rb in gogo_csv-0.0.2
- old
+ new
@@ -1,26 +1,25 @@
require "gogo_csv/version"
+require "gogo_csv/matrix"
+require "gogo_csv/array"
module GogoCsv
require 'csv'
+ require 'matrix'
- def read(path)
- CSV.read(
+ def open(path, format=:matrix)
+ $path = path
+ arys = CSV.read(
File.expand_path(path)
)
- end
- class ::Array
-
- def save!(path)
- raise 'should be array of array' unless arys?
- CSV.open(File.expand_path(path), "wb") do |csv|
- each { |ary| csv << ary }
- end
+ case format
+ when :matrix
+ Matrix[*arys]
+ when :arys
+ arys
end
-
- private def arys?
- all? { |item| item.is_a?(Array) }
- end
-
end
+ module_function :open
end
+
+include GogoCsv