easy_sheet_io 0.1.0 → 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: f9380c502e6f1f1ff929dcbb4b36f9a4f51ec97279eabcd5ad09167ca1ddb4e7
4
- data.tar.gz: 5ec043f6b528a9f7f82d3047f0661ab9e25c2807ebf6281b11dca68b2cc71106
3
+ metadata.gz: 791e3662406be26d6afb90f394f0d585b7c9e956d4cdc200db484be820af4eb8
4
+ data.tar.gz: 7796eacac61646ec19c3d452b9ff738de37546b2a7360374a9f9d5fd9fabda8a
5
5
  SHA512:
6
- metadata.gz: 67927c9b8b989b728a8806a20fed3c45e34165dc605bbc9961e14871a22b4d2e9e9f7a36b0128f81269c1d07fc21204c260c60a88a067d0613b3bf7b423139bd
7
- data.tar.gz: b5ff2cef838ec9b50ef36756b4089c0aae853fa1a0042d1863914ffeb88c8c82531ac0fe26343247052c9128f8895caf5b9d1dc15d08b482b81f25be811b2a42
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/
@@ -10,14 +10,14 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "A simple way to Open .csv, .xls, .xlsx files."
12
12
  spec.description = "A simple way to Open .csv, .xls, .xlsx files. You can convert it to 2D Array, Hash, Dataframe."
13
- spec.homepage = "https://github.com/show-o-atakun/easy_sheet_io_gemspec"
13
+ spec.homepage = "https://github.com/show-o-atakun/easy_sheet_io"
14
14
  spec.license = "MIT"
15
15
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
16
 
17
17
  # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
18
18
 
19
19
  spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/show-o-atakun/easy_sheet_io_gemspec"
20
+ spec.metadata["source_code_uri"] = "https://github.com/show-o-atakun/easy_sheet_io"
21
21
  ## spec.metadata["changelog_uri"] = "https://github.com/show-o-atakun/easy_sheet_io_gemspec"
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasySheetIo
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/easy_sheet_io.rb CHANGED
@@ -4,9 +4,8 @@ require "roo-xls"
4
4
  require "spreadsheet"
5
5
  require "rover"
6
6
  require "daru"
7
- require "./to_csv"
8
- require "./longest_line"
9
-
7
+ require_relative "./to_csv"
8
+ require_relative "./longest_line"
10
9
  require_relative "easy_sheet_io/version"
11
10
 
12
11
  module EasySheetIo
@@ -20,24 +19,30 @@ module EasySheetIo
20
19
 
21
20
  # ##Generate DF from CSV File
22
21
  # **opt candidate= line_from: 1, header: 0
23
- def read_csv(path, format: :hash, **opt)
24
- 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
+
25
26
  ans = to_hash(csv, **opt)
26
27
  return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
27
28
  end
28
29
 
29
30
  # ##Generate DF from Excel File
30
31
  # **opt candidate= line_from: 1, header: 0)
31
- 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)
32
35
  a2d = open_excel(path, sheet_i) # Get 2D Array
36
+ return a2d if format.nil?
37
+
33
38
  ans = to_hash(a2d, **opt)
34
39
  return format==:hash || format=="hash" ? ans : to_df(ans, format: format)
35
40
  end
36
41
 
37
42
  # Convert 2d Array to Hash
38
43
  # ##header: nil -> Default Headers(:column1, column2,...) are generated.
39
- def to_hash(array2d, line_from: 1, header: 0)
40
- output = array2d[line_from..]
44
+ def to_hash(array2d, line_from: 1, line_until: -1, header: 0)
45
+ output = array2d[line_from..line_until]
41
46
  hd = header.nil? ? [*0...(output.longest_line)].map{"column#{_1}"} : array2d[header]
42
47
  output_transpose = output[0].zip(*output[1..])
43
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.0
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-17 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.
@@ -34,12 +34,12 @@ files:
34
34
  - lib/easy_sheet_io/version.rb
35
35
  - lib/longest_line.rb
36
36
  - lib/to_csv.rb
37
- homepage: https://github.com/show-o-atakun/easy_sheet_io_gemspec
37
+ homepage: https://github.com/show-o-atakun/easy_sheet_io
38
38
  licenses:
39
39
  - MIT
40
40
  metadata:
41
- homepage_uri: https://github.com/show-o-atakun/easy_sheet_io_gemspec
42
- source_code_uri: https://github.com/show-o-atakun/easy_sheet_io_gemspec
41
+ homepage_uri: https://github.com/show-o-atakun/easy_sheet_io
42
+ source_code_uri: https://github.com/show-o-atakun/easy_sheet_io
43
43
  post_install_message:
44
44
  rdoc_options: []
45
45
  require_paths: