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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 190b70cd810d3a892a1da5f695df20b53c7c5fb4f4d8117cf10637afbb91a2e1
4
- data.tar.gz: bbd1bc7cfbd26f6cae960fd9f5defcadec8d96a26f7b9f1727c169adc96a008c
3
+ metadata.gz: a7081b6e357ed4f81ee5d68b2d5f9badc8ec78d011baa913fcb82bd6e7791ff7
4
+ data.tar.gz: '083d8baed1ca480c30395649e1c8e9c528052a70d428ec99149ef659ee51ce12'
5
5
  SHA512:
6
- metadata.gz: 007b8d10eef25a31fb62da6192378392d0347024c54a34a31176f0e5f7f142fc2c3a09467a8c1c17e3332c7cb14916a44917e0753b79409c1bfb7d5fb67bd432
7
- data.tar.gz: d9acbc0819e07767d47d386015d1a104d0d712371cbf23e4dc8e812361f5b798a44687d98779e3741035377608078dc4ccd03b4aad17526b03337ef79b9f0dc1
6
+ metadata.gz: 1692e122e054a9931fa0fe95196429f25a7395763b2c27d748b22ef56bbc4409318553d1b23f80fb839058d6dcd0362fa98f12ef268873b0602846829974b816
7
+ data.tar.gz: 6e59b2f33ed3aeb1629c08b373e004407eedec315507df96eb2ecd4ca10b7584fbd940ca10ed4cf8c9e479e65a87bd971dba4e03657b9073780d02b751655709
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_sheet_io (0.3.7)
4
+ easy_sheet_io (0.3.8)
5
5
  daru (>= 0.3)
6
6
  roo-xls (>= 1.2.0)
7
7
  rover-df (>= 0.2.7)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasySheetIo
4
- VERSION = "0.3.7"
4
+ VERSION = "0.3.8"
5
5
  end
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
- def read_csv(path, format: nil, encoding: "utf-8", col_sep: ",", **opt)
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
- return csv if format.nil?
33
-
34
- # Convert Hash or DataFrame
35
- ans = to_hash(csv, **opt)
36
- return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
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
- return a2d if format.nil?
44
-
45
- ans = to_hash(a2d, **opt)
46
- return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
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
- open(path, "w") { _1.write to_csv }
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
- open(path, "w") {|f| f.write self.to_csv}
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.7
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-05 00:00:00.000000000 Z
11
+ date: 2023-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daru