easy_sheet_io 0.2.1 → 0.2.2
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 +1 -0
- data/Gemfile.lock +1 -0
- data/lib/easy_sheet_io/version.rb +1 -1
- data/lib/easy_sheet_io.rb +27 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6de67291cc58a0ab7ea017efd79e847351f71e6790f5f2e4e3fb4462c2ff5f47
|
4
|
+
data.tar.gz: aa0dca360cfa89666b291d8ddeea149399068fbf57f12c422e615c5da03ac71e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cadf3040934873c1a9182000d6b90a9fbad20056e1bd0c17e2fe21929643a2a438832e4fdcdb5519b1def845925526cc3c4df460346affe397a8c05bddf95ce
|
7
|
+
data.tar.gz: 3d7df3a901737bdca5ee7cf8e9399b2d958d51134328ea5ee33ac5e17126847c54ff3e20617ad26b073029afbc790e31e10bef66d18b2d74429f36db417ddef9
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/lib/easy_sheet_io.rb
CHANGED
@@ -31,6 +31,7 @@ module EasySheetIo
|
|
31
31
|
|
32
32
|
return csv if format.nil?
|
33
33
|
|
34
|
+
# Convert Hash or DataFrame
|
34
35
|
ans = to_hash(csv, **opt)
|
35
36
|
return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
|
36
37
|
end
|
@@ -48,7 +49,7 @@ module EasySheetIo
|
|
48
49
|
# Convert 2d Array to Hash
|
49
50
|
# ##header: nil -> Default Headers(:column1, column2,...) are generated.
|
50
51
|
# line_until=nil means the data are picked up until the end line.
|
51
|
-
def to_hash(array2d, line_from: 1, line_until: nil, header: 0)
|
52
|
+
def to_hash(array2d, line_from: 1, line_until: nil, header: 0, symbol_header: false)
|
52
53
|
|
53
54
|
# Define Read Range------------
|
54
55
|
lfrom, luntil = line_from, line_until
|
@@ -67,13 +68,8 @@ module EasySheetIo
|
|
67
68
|
# -----------------------------
|
68
69
|
|
69
70
|
# Define Header----------------
|
70
|
-
|
71
|
-
|
72
|
-
elsif header=="symbol" || header==:symbol
|
73
|
-
hd = [*0...(output.longest_line)].map{"column#{_1}".intern}
|
74
|
-
else
|
75
|
-
hd = array2d[header]
|
76
|
-
end
|
71
|
+
hd = header.nil? ? [*0...(output.longest_line)].map{"column#{_1}"} : check_header(array2d[header])
|
72
|
+
hd = hd.map { _1.intern } if symbol_header
|
77
73
|
# -----------------------------
|
78
74
|
|
79
75
|
# Make Hash(Header => Data Array)
|
@@ -89,7 +85,7 @@ module EasySheetIo
|
|
89
85
|
end
|
90
86
|
end
|
91
87
|
|
92
|
-
# ##Genarate
|
88
|
+
# ##Genarate Array from excel file
|
93
89
|
def open_excel(path, sheet_i, encoding: "utf-8")
|
94
90
|
if /xlsx$/ === path
|
95
91
|
puts "Sorry, encoding option is not supported yet for xlsx file." if encoding != "utf-8"
|
@@ -120,6 +116,28 @@ module EasySheetIo
|
|
120
116
|
|
121
117
|
return a2d
|
122
118
|
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Fix blank or duplicated header
|
122
|
+
def check_header(header_array)
|
123
|
+
ans = header_array.map.with_index do |item, i|
|
124
|
+
if item.nil?
|
125
|
+
"column#{i}"
|
126
|
+
elsif item.kind_of?(String)
|
127
|
+
/^\s*$/ === item ? "column#{i}" : item.gsub(/\s+/, "")
|
128
|
+
else
|
129
|
+
item
|
130
|
+
end
|
131
|
+
end
|
123
132
|
|
133
|
+
dup_check = (0...(header_array.length)).group_by {|i| ans[i]}
|
134
|
+
dup_check.each do |item, i_s|
|
135
|
+
if i_s.length > 1
|
136
|
+
i_s.each_with_index {|i, index_in_i_s| ans[i] = "#{ans[i]}_#{index_in_i_s}"}
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
return ans
|
124
141
|
end
|
142
|
+
|
125
143
|
end
|