easy_sheet_io 0.4.8.1 → 0.4.8.3

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: 88edcacd71fe38c1c41afc2d0de7ab34d432e83d1b1159916dd68d8ecc18776e
4
- data.tar.gz: 468c437396225b78c5bbfd81547faa97bf7eb16bfe6c2e9013427ef8a065e7cd
3
+ metadata.gz: 68608659ae3ff0047c484023e40620ff8fe21a6e4a581bf5e8f8b4ff34f4b522
4
+ data.tar.gz: 1bbfe8f270b425dbdd7aa493e53e27e500561885fb96e93c01ba6682abdc5a49
5
5
  SHA512:
6
- metadata.gz: 3a6b7b24311972cb33a6f97cfbcea6fd00ee81a289129a5e1792b4fcbe5132d23ae5418095872bf208fd2e4a71f4363b7736c83eac0f52a755c1d7006e945a5d
7
- data.tar.gz: f3655048a0b9b931344fef04d5e1fbcbf3b3efa2a543a91a33710da605da5e387aa12a4ad0e65561b3b6b55a2f5613c954d5e60a4b1e25b1597b3268c76659f0
6
+ metadata.gz: 55127eb592a1e4ee2616d084dff54b87d10dbb22c63b845880b52a85f1c2c28c5cf6f064a02a5c970c54d56af6bc3b6e7d065a253a61f8e83a12dfc75dd2d68a
7
+ data.tar.gz: f83ef0ff3cd9b7554348613ac3cef1a5cebc6ea3f0e40ff66a6765bf2925d5baddeb83eb1bbf72418f27056704fe6efe2359fbcd8c2dc81d9a2c496adea136f1
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasySheetIo
4
- VERSION = "0.4.8.1"
4
+ VERSION = "0.4.8.3"
5
5
  end
data/lib/easy_sheet_io.rb CHANGED
@@ -37,14 +37,17 @@ module EasySheetIo
37
37
  if format.to_s == "array"
38
38
  return csv
39
39
  elsif format.to_s == "hash"
40
- return to_hash(csv, **opt)
40
+ h, i = to_hash(csv, **opt)
41
+ return h
41
42
  else # include format.nil? (in this case, convert to Daru::DF).
42
- ans = to_df(to_hash(csv, **opt), format: format)
43
+
44
+ h, ind_orig = to_hash(csv, index: index, **opt)
45
+ ans = to_df(h, format: format)
43
46
 
44
47
  # Converting Encode and Setting index.. rover not supported yet
45
48
  if format.to_s == "daru" || format.nil?
46
49
  ans.convert_enc!(from: encoding, to: "utf-8")
47
- ans.set_index!(index) if index
50
+ ans.index = ind_orig if index
48
51
  end
49
52
 
50
53
  return ans
@@ -59,11 +62,13 @@ module EasySheetIo
59
62
  if format.to_s == "array"
60
63
  return a2d
61
64
  elsif format.to_s == "hash"
62
- return to_hash(a2d, **opt)
65
+ h, i = to_hash(a2d, **opt)
66
+ return h
63
67
  else # include format.nil?
64
- ans = to_df(to_hash(a2d, **opt), format: format)
68
+ h, ind_orig = to_hash(a2d, index: index, **opt)
69
+ ans = to_df(h, format: format)
65
70
  if format.to_s == "daru" || format.nil?
66
- ans.set_index!(index) if index
71
+ ans.index = ind_orig if index
67
72
  end
68
73
  return ans
69
74
  end
@@ -75,7 +80,8 @@ module EasySheetIo
75
80
  def to_hash(array2d, line_from: 1, line_until: nil, line_ignored: nil,
76
81
  column_from: nil, column_until: nil,
77
82
  header: 0, symbol_header: false,
78
- replaced_by_nil: [], analyze_type: true)
83
+ replaced_by_nil: [], analyze_type: true,
84
+ index: nil)
79
85
  ## TODO.. column_from: , column_until:
80
86
 
81
87
  # Define Read Range------------
@@ -91,6 +97,10 @@ module EasySheetIo
91
97
  # And get originally array-----
92
98
  output = array2d[lfrom...luntil]
93
99
  # -----------------------------
100
+
101
+ # Then get data of index-------
102
+ ind_orig = index ? output.map{ _1[index] } : nil
103
+ # -----------------------------
94
104
 
95
105
  # Selecct Column---------------
96
106
  output = output.map { _1[column_from...column_until] } if column_from || column_until
@@ -101,17 +111,27 @@ module EasySheetIo
101
111
  # -----------------------------
102
112
 
103
113
  # Define Header----------------
104
- hd = header.nil? ? [*0...(output.longest_line)].map{"column#{_1}"} : check_header(array2d[header])
114
+ if header
115
+ hd = check_header(array2d[header])[column_from...column_until]
116
+ else
117
+ hd = [*0...(output.longest_line)].map{"column#{_1}"}
118
+ end
119
+ # hd = header.nil? ? [*0...(output.longest_line)].map{"column#{_1}"} : check_header(array2d[header])
120
+
105
121
  hd = hd.map { _1.intern } if symbol_header
106
122
  # -----------------------------
107
123
 
108
124
  # Make Hash(Header => Data Array)
109
- return hd.each_with_object({}).with_index {|(hdr, hash), i| hash[hdr]=output_transpose[i]}
125
+ return hd.each_with_object({}).with_index {|(hdr, hash), i| hash[hdr]=output_transpose[i]}, ind_orig
110
126
  end
111
127
 
112
128
  # Convert Hash to DataFrame
113
129
  def to_df(d, format: :daru)
114
- return format.to_s == "daru" || format.nil? ? Daru::DataFrame.new(d) : Rover::DataFrame.new(d)
130
+ if format.to_s == "daru" || format.nil?
131
+ Daru::DataFrame.new(d)
132
+ else
133
+ Rover::DataFrame.new(d)
134
+ end
115
135
  end
116
136
 
117
137
  #----------------------------
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.4.8.1
4
+ version: 0.4.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - show-o-atakun