ruby-xlsx-to-md 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 04b972bb134e07ea537c1e0431f79d9bffc183f2ba1fbc742800fdea272c9a3c
4
+ data.tar.gz: ec40486fa5398ac8486d14d32964042162493768833c7b4ad36aaddabf022782
5
+ SHA512:
6
+ metadata.gz: 15c2924fe19691acf5e4a73179abec751be66efe31e8c6deefcc5acd1f396e7af7d435c6d2e0243433bdc38c7f79b458d7c40f2e8d800efd3df4106abfa7b836
7
+ data.tar.gz: edb041679a40536a9fe381a78ae0e05fe0b4bc02f41ba76eed9fa035b797d074b6412ab5ffe7fcc6f8d89ef57314d28b98294995082f8cc485e388217cdbee91
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # ruby-xlsx-to-md
2
+
3
+ A Ruby gem for converting XLSX spreadsheets to Markdown.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem "ruby-xlsx-to-md"
11
+ ```
12
+
13
+ Then execute:
14
+
15
+ ```sh
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```sh
22
+ gem install ruby-xlsx-to-md
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require "ruby_xlsx_to_md"
29
+
30
+ RubyXlsxToMd.convert("spreadsheet.xlsx")
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bundle install` to install dependencies. Run `bundle exec rake test` to run the test suite.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |task|
7
+ task.libs << "test"
8
+ task.pattern = "test/**/*_test.rb"
9
+ end
10
+
11
+ task default: :test
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyXlsxToMd
4
+ module Encoding
5
+ BOMS = {
6
+ "\xEF\xBB\xBF".b => "UTF-8",
7
+ "\xFF\xFE".b => "UTF-16LE",
8
+ "\xFE\xFF".b => "UTF-16BE",
9
+ }.freeze
10
+
11
+ def self.detect(bytes)
12
+ BOMS.each do |bom, encoding|
13
+ return encoding if bytes.start_with?(bom)
14
+ end
15
+
16
+ utf8 = bytes.dup.force_encoding("UTF-8")
17
+ return "UTF-8" if utf8.valid_encoding?
18
+
19
+ "Windows-1252"
20
+ end
21
+
22
+ def self.to_utf8(bytes)
23
+ encoding = detect(bytes)
24
+
25
+ text = bytes.dup.force_encoding(encoding)
26
+ text = text.encode("UTF-8", invalid: :replace, undef: :replace)
27
+ text.delete_prefix!("\uFEFF")
28
+ text
29
+ end
30
+
31
+ def self.ensure_utf8(value)
32
+ return value if value.encoding == ::Encoding::UTF_8 && value.valid_encoding?
33
+
34
+ to_utf8(value.b)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyXlsxToMd
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubyXL"
4
+
5
+ require_relative "ruby_xlsx_to_md/version"
6
+ require_relative "ruby_xlsx_to_md/encoding"
7
+
8
+ module RubyXlsxToMd
9
+ class Error < StandardError; end
10
+
11
+ def self.convert(path)
12
+ workbook = RubyXL::Parser.parse(path)
13
+
14
+ workbook.worksheets.map do |sheet|
15
+ "---\n#{sheet.sheet_name}\n---\n#{sheet_to_markdown(sheet)}"
16
+ end.join("\n\n")
17
+ end
18
+
19
+ def self.sheet_to_markdown(sheet)
20
+ rows = sheet.sheet_data
21
+ min_c = nil ; max_c = nil
22
+
23
+ # Find column range across all rows
24
+ rows.rows.each_with_index do |row, _ri|
25
+ next if row.nil?
26
+ row.cells.each_with_index do |cell, ci|
27
+ next if cell.nil? || (cell.value.nil? || cell.value.to_s.strip.empty?)
28
+ min_c = ci if min_c.nil? || ci < min_c
29
+ max_c = ci if max_c.nil? || ci > max_c
30
+ end
31
+ end
32
+
33
+ return "" if min_c.nil?
34
+
35
+ lines = []
36
+
37
+ header = "| Row # |"
38
+ (min_c..max_c).each { |c| header += " #{col_letter(c)} |" }
39
+ lines << header
40
+
41
+ sep = "|---|"
42
+ (min_c..max_c).each { |_| sep += "---|" }
43
+ lines << sep
44
+
45
+ rows.rows.each_with_index do |row, ri|
46
+ vals = (min_c..max_c).map do |ci|
47
+ raw = row&.[](ci)&.value
48
+ val = raw.to_s.empty? ? "" : Encoding.ensure_utf8(raw.to_s)
49
+ val.include?("|") ? val.gsub("|", "\\|") : val
50
+ end
51
+ lines << "| #{ri + 1} | #{vals.join(" | ")} |"
52
+ end
53
+
54
+ lines.join("\n")
55
+ end
56
+
57
+ def self.col_letter(index)
58
+ letters = ""
59
+ loop do
60
+ letters = ((65 + (index % 26)).chr) + letters
61
+ index = index / 26 - 1
62
+ break if index < 0
63
+ end
64
+ letters
65
+ end
66
+
67
+ end
data/mise.toml ADDED
@@ -0,0 +1,5 @@
1
+ [tools]
2
+ ruby = "3.4.7"
3
+
4
+ [tasks]
5
+ test = "bundle exec rake test TESTOPTS='--verbose'"
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/ruby_xlsx_to_md/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruby-xlsx-to-md"
7
+ spec.version = RubyXlsxToMd::VERSION
8
+ spec.authors = ["Victor"]
9
+ spec.email = ["victorgt2406@github.com"]
10
+
11
+ spec.summary = "Convert XLSX spreadsheets to Markdown."
12
+ spec.description = "A Ruby gem for converting XLSX spreadsheets to Markdown."
13
+ spec.homepage = "https://github.com/victorgt2406/ruby-xlsx-to-md"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.1.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
20
+
21
+ spec.files = Dir.chdir(__dir__) do
22
+ `git ls-files -z`.split("\x0").reject do |file|
23
+ file.start_with?("test/", "spec/", "features/", ".git", "pkg/")
24
+ end
25
+ end
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_dependency "rubyXL", "~> 3.4"
29
+
30
+ spec.add_development_dependency "minitest", "~> 5.0"
31
+ spec.add_development_dependency "rake", "~> 13.0"
32
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-xlsx-to-md
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Victor
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rubyXL
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '3.4'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '3.4'
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '5.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '13.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ description: A Ruby gem for converting XLSX spreadsheets to Markdown.
55
+ email:
56
+ - victorgt2406@github.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - Gemfile
62
+ - LICENSE.txt
63
+ - README.md
64
+ - Rakefile
65
+ - lib/ruby_xlsx_to_md.rb
66
+ - lib/ruby_xlsx_to_md/encoding.rb
67
+ - lib/ruby_xlsx_to_md/version.rb
68
+ - mise.toml
69
+ - ruby-xlsx-to-md.gemspec
70
+ homepage: https://github.com/victorgt2406/ruby-xlsx-to-md
71
+ licenses:
72
+ - MIT
73
+ metadata:
74
+ homepage_uri: https://github.com/victorgt2406/ruby-xlsx-to-md
75
+ source_code_uri: https://github.com/victorgt2406/ruby-xlsx-to-md
76
+ changelog_uri: https://github.com/victorgt2406/ruby-xlsx-to-md/blob/main/CHANGELOG.md
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 3.1.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.6.9
92
+ specification_version: 4
93
+ summary: Convert XLSX spreadsheets to Markdown.
94
+ test_files: []