easy_sheet_io 0.4.6.1 → 0.4.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 685887cb42121abd31ee9247b6a6567853d69990b1e00ac8332a1e6a6b7f6eb7
4
- data.tar.gz: 5b1871486be2cfce04639ec8ab49bd64c074f0cfd81f967c91f7242ce27d9b0a
3
+ metadata.gz: a53b3053320aed73cc23e53314ddbad656a0d7567f9012a4bf1388c7e44958c0
4
+ data.tar.gz: 971ad3bfc3a5211493c31886a5487f5f19a4ddda8b7a71a5be3c4a6cf10d2761
5
5
  SHA512:
6
- metadata.gz: 6509dce129c5732759c37ccdb8168666b1b39be910b56a9f175e076f5ea7c8d0924f891db0bfa2eb7810e1b631a88989b1d780baf8607039824c33398e14f504
7
- data.tar.gz: e3135fe8dfb8601557fccd0a0c3b7185e86cc0e27a4b7cc43f230d42090e80a9b0003851c68731a6a66de2709b88a21bc4bea0a5d74a797e145c33252c67f503
6
+ metadata.gz: 4b24c4ffdb2c549ab9457362c0d16234808f3b98e8140e1a656771749203aee0fd2d8aafd90590c98ffc19358eda892cc45e4887702884560c92cc7950101a75
7
+ data.tar.gz: 952d816e49b326fb3b266a5ae00ff4d649b337e080451ca348068975b333384f311b59471db41084cdee584746e43fd9a88c34b2b91b6ec94834eb5147d1f875
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasySheetIo
4
- VERSION = "0.4.6.1"
4
+ VERSION = "0.4.7.1"
5
5
  end
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
- ans.set_index! if format.to_s == "daru" || format.nil?
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
- return to_df(to_hash(a2d, **opt), format: format)
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", format: nil)
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! if format.to_s == "daru" || format.nil?
47
+ self.encode_vectors!
47
48
  end
49
+ #####################
48
50
 
49
- # rover not suppoted yet
50
- def set_index!
51
- self.index = self[0]
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.6.1
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-10 00:00:00.000000000 Z
11
+ date: 2023-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: daru