easy_sheet_io 0.1.2 → 0.1.4

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: 2b4655b4dbf3e5a8bbb152f70018068103bc335f4f2d855b82bf0ecb27eb045c
4
- data.tar.gz: a07f5bb08b09eb724b8a38d67dc7fe6e571ed040d558e76cff2a164850e28e09
3
+ metadata.gz: 791e3662406be26d6afb90f394f0d585b7c9e956d4cdc200db484be820af4eb8
4
+ data.tar.gz: 7796eacac61646ec19c3d452b9ff738de37546b2a7360374a9f9d5fd9fabda8a
5
5
  SHA512:
6
- metadata.gz: 883e6250a702be56a3a072129494bd8650fcb09db21ba2251fc9668dc078d0f3b7747889441702104a5772b2452ec85d00bd580c2f982db66bd33a496739f8db
7
- data.tar.gz: 73d9b766d85d9489bfb5806fd0bb2e1ebba7333cb17511358ff0a0bf1541d664707193debf4097c394b35e126789fb1ec07ef37aefc4229c7cddb946cf36332f
6
+ metadata.gz: 991506127b66bfdd211f99ec00554dcca3ad521274d3c712389d3f346cf35f4d0b1c5e0478817f9ead1a915aa89c34a88abf49502ee054d30a41a02f19068510
7
+ data.tar.gz: 6eb892fa842a1a522e939c432e66c0aef9384b37b4bae3b454bb9a82628a2dbd3b3c1cb3d13192b71cf915a7b886858fbb31331b5fa6f03a148baacefd5a611b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_sheet_io (0.1.0)
4
+ easy_sheet_io (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasySheetIo
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/easy_sheet_io.rb CHANGED
@@ -19,24 +19,30 @@ module EasySheetIo
19
19
 
20
20
  # ##Generate DF from CSV File
21
21
  # **opt candidate= line_from: 1, header: 0
22
- def read_csv(path, format: :hash, **opt)
23
- csv = CSV.parse(File.open path, &:read) # Get 2D Array
22
+ def read_csv(path, format: nil, encoding: "utf-8", **opt)
23
+ csv = CSV.parse(File.open path, encoding: encoding, &:read) # Get 2D Array
24
+ return csv if format.nil?
25
+
24
26
  ans = to_hash(csv, **opt)
25
27
  return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
26
28
  end
27
29
 
28
30
  # ##Generate DF from Excel File
29
31
  # **opt candidate= line_from: 1, header: 0)
30
- def read_excel(path, sheet_i: 0, format: :hash, **opt)
32
+ # !encoding parameter is not allowed yet
33
+ # !(Finally, I want to make it automatically recognize encoding of file).
34
+ def read_excel(path, sheet_i: 0, format: nil, **opt)
31
35
  a2d = open_excel(path, sheet_i) # Get 2D Array
36
+ return a2d if format.nil?
37
+
32
38
  ans = to_hash(a2d, **opt)
33
39
  return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
34
40
  end
35
41
 
36
42
  # Convert 2d Array to Hash
37
43
  # ##header: nil -> Default Headers(:column1, column2,...) are generated.
38
- def to_hash(array2d, line_from: 1, header: 0)
39
- output = array2d[line_from..]
44
+ def to_hash(array2d, line_from: 1, line_until: -1, header: 0)
45
+ output = array2d[line_from..line_until]
40
46
  hd = header.nil? ? [*0...(output.longest_line)].map{"column#{_1}"} : array2d[header]
41
47
  output_transpose = output[0].zip(*output[1..])
42
48
 
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.1.2
4
+ version: 0.1.4
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: 2022-03-18 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple way to Open .csv, .xls, .xlsx files. You can convert it to 2D
14
14
  Array, Hash, Dataframe.