flex_csv 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/flex_csv.rb +24 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0c8fc838516607bcf8d6742f35003ff84901c68f
|
4
|
+
data.tar.gz: f8e8c1ba379aae036a83067cbb1b88b8f61f1c53
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 146a068f367b8b1a40441a8a273c7325ac160cc5f66a563eed4eb4d365477fb1a9aabc3936a7b5f0747eca983b3f0028ff46e61397feb578514201f00e0dcaf0
|
7
|
+
data.tar.gz: 8f135fe727920d1b3e72946646c09471fbd91eb991090f69310a20387ea5a3a7a93007dbbe39a82855318caeea9a82951f95b301061ea9b34cfaadc31e4887b6
|
data/lib/flex_csv.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
class FlexCSV
|
4
|
+
def initialize (input, args = {})
|
5
|
+
rows = []
|
6
|
+
case input.first
|
7
|
+
when Hash
|
8
|
+
rows << input.first.keys
|
9
|
+
input.each { |hash| rows << hash.values }
|
10
|
+
when String
|
11
|
+
rows << eval(input.first).keys
|
12
|
+
input.each { |string| rows << eval(string).values }
|
13
|
+
else
|
14
|
+
raise ArgumentError
|
15
|
+
end
|
16
|
+
path = args[:path] || __dir__ + '/temp.csv'
|
17
|
+
open = args[:path].nil? ? false : args[:open]
|
18
|
+
|
19
|
+
CSV.open(path, 'w') do |csv|
|
20
|
+
rows.each { |row| csv << row}
|
21
|
+
end
|
22
|
+
`open #{path}` if open
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flex_csv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugene Lai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: To do
|
14
|
+
email: ejt.lai@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/flex_csv.rb
|
20
|
+
homepage:
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.5.2
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Just a simple yet flexible csv utility
|
43
|
+
test_files: []
|