easy_sheet_io 0.2.3 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff453d19575a146798eccf86d2f5071e0e7fb404ad72280932d327f5a86ad589
4
- data.tar.gz: a06d0d24db9e1e723164bd11f5aa63e0564d1e69a298369f57cd59d8d7b2863d
3
+ metadata.gz: 1883fab0e5e9b2314c463d6e09f293937a259939da884f204c12a587b5468b85
4
+ data.tar.gz: f6d670676aa90174b8c63823aa70662266d84333a1dc70b15e04e983fe9558fa
5
5
  SHA512:
6
- metadata.gz: aa4f65e4d22bdec3f2435671a789cf72e8e4b528bd2b357585a6f0b0114edf4cb4209d549232fd4184853f6223e46a29278776a7949cb558fd24cb82455b9017
7
- data.tar.gz: 5bd605a6b4d35e6e084a58bdc7172ccaf765984d4d1610c0bb5e01de3d30619cd5042ec944c45d24a768d6501a52b19b315a6d1d686830359953d64251748a0c
6
+ metadata.gz: f7fbc846a757c052948db4f3cd058d1aecac17c8fd9f521a4d97dbf631d721d6dae8f3701be50b82fcfadf4a85e0bf522f10783eb4adb1e891270dba50345c9a
7
+ data.tar.gz: a39b1ae932102f750363ec6f976118b9be7ed43ad8826d078f946e8924935f3fc09593d2ed4b7ee992c2e9b0c13ba03b3398edbc0ea9b8c9a3f45c3de0edaed2
data/Gemfile.lock CHANGED
@@ -1,7 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_sheet_io (0.2.2)
4
+ easy_sheet_io (0.3.0)
5
+ daru (>= 0.3)
6
+ rake (~> 13.0)
7
+ roo-xls (>= 1.2.0)
8
+ rover-df (>= 0.2.7)
9
+ rspec (~> 3.0)
10
+ rubocop (~> 0.80)
11
+ smarter_csv (>= 1.4.2)
12
+ spreadsheet (>= 1.3.0)
5
13
 
6
14
  GEM
7
15
  remote: https://rubygems.org/
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasySheetIo
4
- VERSION = "0.2.3"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/easy_sheet_io.rb CHANGED
@@ -66,8 +66,8 @@ module EasySheetIo
66
66
 
67
67
  # Define Data Array------------
68
68
  output = array2d[lfrom...luntil]
69
- output = fix_array(output, replace_to_nil, analyze_type)
70
69
  output_transpose = output[0].zip(*output[1..])
70
+ output_transpose = fix_array(output_transpose, replace_to_nil, analyze_type)
71
71
  # -----------------------------
72
72
 
73
73
  # Define Header----------------
@@ -129,15 +129,47 @@ module EasySheetIo
129
129
  def fix_array(array2d, replace_to_nil, analyze_type)
130
130
  ans = array2d
131
131
 
132
- if replace_nil.length > 0
133
- ans = ans.map { _1.map {|cell| replace_nil.include?(cell) ? nil : cell } }
132
+ ## Replace Blank or User-Selected Value
133
+ ans = ans.map do |column|
134
+ column.map { |cell| replace_to_nil.include?(cell) || /^\s*$/ === cell ? nil : cell }
134
135
  end
135
-
136
+
137
+ ## Replace Number Values to Integer or Float
136
138
  if analyze_type
137
- ans = ans.map do |column|
139
+ ans = ans.map.with_index do |column, i|
140
+ type_of_column = :any
141
+ column.each { |cell| type_of_column = recognize_type(cell, type_of_column) }
138
142
 
143
+ # p type_of_column
144
+ case type_of_column
145
+ when :int
146
+ column.map { _1.nil? ? nil : _1.to_i }
147
+ when :float
148
+ column.map { _1.nil? ? nil : _1.to_f }
149
+ else
150
+ column
151
+ end
139
152
  end
140
153
  end
154
+
155
+ return ans
156
+ end
157
+
158
+ def recognize_type(str, expected)
159
+ return expected if str.nil?
160
+
161
+ order = {:any => 0, :int => 1, :float => 2, :string => 3}
162
+ if /^\s*(-|\+)?\d+\s*$/ === str
163
+ type_of_str = :int
164
+ elsif /^\s*(-|\+)?\d*\.\d*\s*$/ === str || /^\s*(-|\+)?(\d*\.\d+|\d+)(e|E)(-|\+)?\d+\s*$/ === str
165
+ type_of_str = :float
166
+ else
167
+ type_of_str = :string
168
+ end
169
+
170
+ # p "#{type_of_str}, #{str}" if order[type_of_str] > order[expected]
171
+
172
+ return order[type_of_str] > order[expected] ? type_of_str : expected
141
173
  end
142
174
 
143
175
  # Fix blank or duplicated header
@@ -147,7 +179,8 @@ module EasySheetIo
147
179
  if item.nil?
148
180
  "column#{i}"
149
181
  elsif item.kind_of?(String)
150
- /^\s*$/ === item ? "column#{i}" : item.gsub(/\s+/, "")
182
+ temp = /^\s*$/ === item ? "column#{i}" : item.gsub(/\s+/, "")
183
+ /^\d+$/ === temp ? "column#{i}" : temp
151
184
  else
152
185
  item
153
186
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_sheet_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - show-o-atakun