easy_sheet_io 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/easy_sheet_io/version.rb +1 -1
- data/lib/easy_sheet_io.rb +11 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 791e3662406be26d6afb90f394f0d585b7c9e956d4cdc200db484be820af4eb8
|
4
|
+
data.tar.gz: 7796eacac61646ec19c3d452b9ff738de37546b2a7360374a9f9d5fd9fabda8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 991506127b66bfdd211f99ec00554dcca3ad521274d3c712389d3f346cf35f4d0b1c5e0478817f9ead1a915aa89c34a88abf49502ee054d30a41a02f19068510
|
7
|
+
data.tar.gz: 6eb892fa842a1a522e939c432e66c0aef9384b37b4bae3b454bb9a82628a2dbd3b3c1cb3d13192b71cf915a7b886858fbb31331b5fa6f03a148baacefd5a611b
|
data/Gemfile.lock
CHANGED
data/lib/easy_sheet_io.rb
CHANGED
@@ -19,24 +19,30 @@ module EasySheetIo
|
|
19
19
|
|
20
20
|
# ##Generate DF from CSV File
|
21
21
|
# **opt candidate= line_from: 1, header: 0
|
22
|
-
def read_csv(path, format: :
|
23
|
-
csv = CSV.parse(File.open path, &:read) # Get 2D Array
|
22
|
+
def read_csv(path, format: nil, encoding: "utf-8", **opt)
|
23
|
+
csv = CSV.parse(File.open path, encoding: encoding, &:read) # Get 2D Array
|
24
|
+
return csv if format.nil?
|
25
|
+
|
24
26
|
ans = to_hash(csv, **opt)
|
25
27
|
return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
|
26
28
|
end
|
27
29
|
|
28
30
|
# ##Generate DF from Excel File
|
29
31
|
# **opt candidate= line_from: 1, header: 0)
|
30
|
-
|
32
|
+
# !encoding parameter is not allowed yet
|
33
|
+
# !(Finally, I want to make it automatically recognize encoding of file).
|
34
|
+
def read_excel(path, sheet_i: 0, format: nil, **opt)
|
31
35
|
a2d = open_excel(path, sheet_i) # Get 2D Array
|
36
|
+
return a2d if format.nil?
|
37
|
+
|
32
38
|
ans = to_hash(a2d, **opt)
|
33
39
|
return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
|
34
40
|
end
|
35
41
|
|
36
42
|
# Convert 2d Array to Hash
|
37
43
|
# ##header: nil -> Default Headers(:column1, column2,...) are generated.
|
38
|
-
def to_hash(array2d, line_from: 1, header: 0)
|
39
|
-
output = array2d[line_from..]
|
44
|
+
def to_hash(array2d, line_from: 1, line_until: -1, header: 0)
|
45
|
+
output = array2d[line_from..line_until]
|
40
46
|
hd = header.nil? ? [*0...(output.longest_line)].map{"column#{_1}"} : array2d[header]
|
41
47
|
output_transpose = output[0].zip(*output[1..])
|
42
48
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_sheet_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- show-o-atakun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple way to Open .csv, .xls, .xlsx files. You can convert it to 2D
|
14
14
|
Array, Hash, Dataframe.
|