easy_sheet_io 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/easy_sheet_io/version.rb +1 -1
- data/lib/easy_sheet_io.rb +19 -10
- data/lib/to_csv.rb +13 -4
- 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: a7081b6e357ed4f81ee5d68b2d5f9badc8ec78d011baa913fcb82bd6e7791ff7
|
4
|
+
data.tar.gz: '083d8baed1ca480c30395649e1c8e9c528052a70d428ec99149ef659ee51ce12'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1692e122e054a9931fa0fe95196429f25a7395763b2c27d748b22ef56bbc4409318553d1b23f80fb839058d6dcd0362fa98f12ef268873b0602846829974b816
|
7
|
+
data.tar.gz: 6e59b2f33ed3aeb1629c08b373e004407eedec315507df96eb2ecd4ca10b7584fbd940ca10ed4cf8c9e479e65a87bd971dba4e03657b9073780d02b751655709
|
data/Gemfile.lock
CHANGED
data/lib/easy_sheet_io.rb
CHANGED
@@ -19,7 +19,8 @@ module EasySheetIo
|
|
19
19
|
|
20
20
|
# ##Generate Array from CSV File, and convert it to Hash or DataFrame.
|
21
21
|
# **opt candidate= line_from: 1, header: 0
|
22
|
-
|
22
|
+
# ver. 0.3.8~ default format=:daru
|
23
|
+
def read_csv(path, format: :daru, encoding: "utf-8", col_sep: ",", **opt)
|
23
24
|
# Get 2D Array
|
24
25
|
begin
|
25
26
|
csv = CSV.parse(File.open(path, encoding: encoding, &:read), col_sep: col_sep)
|
@@ -29,21 +30,29 @@ module EasySheetIo
|
|
29
30
|
csv = CSV.parse(File.open(path, encoding: "cp932", &:read), col_sep: col_sep)
|
30
31
|
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
if format.to_s == "array"
|
34
|
+
return csv
|
35
|
+
elsif format.to_s == "hash"
|
36
|
+
return to_hash(csv, **opt)
|
37
|
+
else # include format.nil?
|
38
|
+
ans = to_df(to_hash(csv, **opt), format: format)
|
39
|
+
ans.convert_enc!(from: encoding, to: "utf-8") if encoding != "utf-8"
|
40
|
+
return ans
|
41
|
+
end
|
37
42
|
end
|
38
43
|
|
39
44
|
# ##Generate Array from EXCEL File, and convert it to Hash or DataFrame.
|
40
45
|
# **opt candidate= line_from: 1, header: 0)
|
41
46
|
def read_excel(path, sheet_i: 0, format: nil, encoding: "utf-8", **opt)
|
42
47
|
a2d = open_excel(path, sheet_i, encoding: encoding) # Get 2D Array
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
|
49
|
+
if format.to_s == "array"
|
50
|
+
return a2d
|
51
|
+
elsif format.to_s == "hash"
|
52
|
+
return to_hash(a2d, **opt)
|
53
|
+
else # include format.nil?
|
54
|
+
return to_df(to_hash(a2d, **opt), format: format)
|
55
|
+
end
|
47
56
|
end
|
48
57
|
|
49
58
|
# Convert 2d Array to Hash
|
data/lib/to_csv.rb
CHANGED
@@ -14,8 +14,9 @@ class Daru::DataFrame
|
|
14
14
|
return ans
|
15
15
|
end
|
16
16
|
|
17
|
-
def write_csv(path)
|
18
|
-
|
17
|
+
def write_csv(path, encoding: nil)
|
18
|
+
enc = encoding.nil? ? "" : ":#{encoding}"
|
19
|
+
open(path, "w#{enc}") { _1.write to_csv }
|
19
20
|
end
|
20
21
|
|
21
22
|
# To avoid bug about adding column to Daru::DataFrame
|
@@ -24,13 +25,21 @@ class Daru::DataFrame
|
|
24
25
|
self.rename_vectors({vecname => vecname})
|
25
26
|
end
|
26
27
|
|
28
|
+
# ver.0.3.8~ Convert Daru::DF encoding
|
29
|
+
def convert_enc!(from: "cp932", to: "utf-8")
|
30
|
+
self.vectors.each do |col|
|
31
|
+
self[col] = self[col].each {|val| val.encode!(to, from_encoding: from) } if self[col][0].is_a?(String)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
27
35
|
alias_method :addvec, :add_vector
|
28
36
|
end
|
29
37
|
|
30
38
|
class Rover::DataFrame
|
31
39
|
# Rover#to_csv is already exist.
|
32
40
|
|
33
|
-
def write_csv(path)
|
34
|
-
|
41
|
+
def write_csv(path, encoding: nil)
|
42
|
+
enc = encoding.nil? ? "" : ":#{encoding}"
|
43
|
+
open(path, "w#{enc}") {|f| f.write self.to_csv}
|
35
44
|
end
|
36
45
|
end
|
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.3.
|
4
|
+
version: 0.3.8
|
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: 2023-02-
|
11
|
+
date: 2023-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: daru
|