easy_sheet_io 0.4.6.1 → 0.4.7.1
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/lib/easy_sheet_io/version.rb +1 -1
- data/lib/easy_sheet_io.rb +12 -6
- data/lib/to_csv.rb +7 -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: a53b3053320aed73cc23e53314ddbad656a0d7567f9012a4bf1388c7e44958c0
|
4
|
+
data.tar.gz: 971ad3bfc3a5211493c31886a5487f5f19a4ddda8b7a71a5be3c4a6cf10d2761
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b24c4ffdb2c549ab9457362c0d16234808f3b98e8140e1a656771749203aee0fd2d8aafd90590c98ffc19358eda892cc45e4887702884560c92cc7950101a75
|
7
|
+
data.tar.gz: 952d816e49b326fb3b266a5ae00ff4d649b337e080451ca348068975b333384f311b59471db41084cdee584746e43fd9a88c34b2b91b6ec94834eb5147d1f875
|
data/lib/easy_sheet_io.rb
CHANGED
@@ -20,7 +20,7 @@ module EasySheetIo
|
|
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
|
+
def read_csv(path, format: :daru, encoding: "utf-8", col_sep: ",", index: nil, **opt)
|
24
24
|
## TODO.. index: option that designate column number to generate DF index.
|
25
25
|
## That is, revicing set_index method.
|
26
26
|
|
@@ -40,10 +40,12 @@ module EasySheetIo
|
|
40
40
|
return to_hash(csv, **opt)
|
41
41
|
else # include format.nil? (in this case, convert to Daru::DF).
|
42
42
|
ans = to_df(to_hash(csv, **opt), format: format)
|
43
|
-
ans.convert_enc!(from: encoding, to: "utf-8", format: format) # if encoding != "utf-8"
|
44
43
|
|
45
|
-
# Setting index.. rover not supported yet
|
46
|
-
|
44
|
+
# Converting Encode and Setting index.. rover not supported yet
|
45
|
+
if format.to_s == "daru" || format.nil?
|
46
|
+
ans.convert_enc!(from: encoding, to: "utf-8")
|
47
|
+
ans.set_index!(index) if index
|
48
|
+
end
|
47
49
|
|
48
50
|
return ans
|
49
51
|
end
|
@@ -51,7 +53,7 @@ module EasySheetIo
|
|
51
53
|
|
52
54
|
# ##Generate Array from EXCEL File, and convert it to Hash or DataFrame.
|
53
55
|
# **opt candidate= line_from: 1, header: 0)
|
54
|
-
def read_excel(path, sheet_i: 0, format: :daru, encoding: "utf-8", **opt)
|
56
|
+
def read_excel(path, sheet_i: 0, format: :daru, encoding: "utf-8", index: nil, **opt)
|
55
57
|
a2d = open_excel(path, sheet_i, encoding: encoding) # Get 2D Array
|
56
58
|
|
57
59
|
if format.to_s == "array"
|
@@ -59,7 +61,11 @@ module EasySheetIo
|
|
59
61
|
elsif format.to_s == "hash"
|
60
62
|
return to_hash(a2d, **opt)
|
61
63
|
else # include format.nil?
|
62
|
-
|
64
|
+
ans = to_df(to_hash(a2d, **opt), format: format)
|
65
|
+
if format.to_s == "daru" || format.nil?
|
66
|
+
ans.set_index!(index) if index
|
67
|
+
end
|
68
|
+
return ans
|
63
69
|
end
|
64
70
|
end
|
65
71
|
|
data/lib/to_csv.rb
CHANGED
@@ -25,6 +25,7 @@ class Daru::DataFrame
|
|
25
25
|
self.rename_vectors({vecname => vecname})
|
26
26
|
end
|
27
27
|
|
28
|
+
### エンコード関連 ###
|
28
29
|
# vector_i番目のヘッダー名を読めるようにエンコード
|
29
30
|
def encode_vector_name(vector_i)
|
30
31
|
if self.vectors.to_a[vector_i].is_a?(String)
|
@@ -38,17 +39,18 @@ class Daru::DataFrame
|
|
38
39
|
end
|
39
40
|
|
40
41
|
# ver.0.3.8~ Convert Daru::DF encoding
|
41
|
-
def convert_enc!(from: "cp932", to: "utf-8"
|
42
|
+
def convert_enc!(from: "cp932", to: "utf-8")
|
42
43
|
self.vectors.each do |col|
|
43
44
|
self[col] = self[col].each {|val| val.encode!(to, from_encoding: from) if val.is_a?(String)}
|
44
45
|
end
|
45
46
|
|
46
|
-
self.encode_vectors!
|
47
|
+
self.encode_vectors!
|
47
48
|
end
|
49
|
+
#####################
|
48
50
|
|
49
|
-
# rover not suppoted yet
|
50
|
-
def set_index!
|
51
|
-
self.index = self[
|
51
|
+
# rover not suppoted yet about indexing
|
52
|
+
def set_index!(indexcolumn)
|
53
|
+
self.index = self[indexcolumn]
|
52
54
|
end
|
53
55
|
|
54
56
|
alias_method :addvec, :add_vector
|
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.4.
|
4
|
+
version: 0.4.7.1
|
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-09-
|
11
|
+
date: 2023-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: daru
|