csv2dokuwiki_tab 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: 51f87c2a5374ea48de27f2c6571d03098892db75cdcd913081cbbc94362adae0
4
+ data.tar.gz: e8c0402fa8f41db866e74863d18cec46bc1f5404c1f3a440eb6fa7b0df51a86e
5
+ SHA512:
6
+ metadata.gz: acf3d5a87db55c2493f0301c5df707de2ed0e8f427582d1f19d9c2782a47b9a8f7c6fb22bb05ffbdcabe323e7e99ec98c6fc2d1605b299c90b8ba2309f9ef8ee
7
+ data.tar.gz: c9e7d2e0ead4804e5c32230a1491a1988788421108aa9d28ab5f8fa7509efc8422f1b1504f8ec7f638299294747b4c269287fefe1a9aff6a89a56f369b4e5924
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Csv2dokuwikiTab
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/csv2dokuwiki_tab`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/csv2dokuwiki_tab.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,4 @@
1
+ Name,Age,Country
2
+ Alice,30,USA
3
+ Bob,25,Canada
4
+ Charlie,35,UK
@@ -0,0 +1,4 @@
1
+ Name Age Country
2
+ Alice 30 USA
3
+ Bob 25 Canada
4
+ Charlie 35 UK
@@ -0,0 +1,44 @@
1
+ require_relative "../lib/csv2dokuwiki_tab"
2
+ require "optparse"
3
+
4
+ def parse_options
5
+ options = {}
6
+ header_type = Csv2dokuwikiTab::HEADER_ROW
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: csv_to_dokuwiki_tab.rb [options]"
9
+
10
+ opts.on("-f FILE", "--file FILE", "CSV file to convert") do |f|
11
+ options[:file] = f
12
+ end
13
+ opts.on("-d TYPE", "--header TYPE", "Heading type. 1=1st row, 2=1st column, 3=both 1&2, 0=none, default: 1") do |d|
14
+ case d
15
+ when "1"
16
+ header_type = Csv2dokuwikiTab::HEADER_ROW
17
+ when "2"
18
+ header_type = Csv2dokuwikiTab::HEADER_COL
19
+ when "3"
20
+ header_type = Csv2dokuwikiTab::HEADER_BOTH
21
+ when "0"
22
+ header_type = Csv2dokuwikiTab::HEADER_NONE
23
+ else
24
+ warn "Unknown header type '#{d}', using default."
25
+ header_type = Csv2dokuwikiTab::HEADER_ROW
26
+ end
27
+ end
28
+ opts.on("-h", "--help", "Prints this help") do
29
+ puts opts
30
+ exit
31
+ end
32
+ end.parse!
33
+ unless options[:file]
34
+ warn "Error: CSV file must be specified with -f"
35
+ exit 1
36
+ end
37
+ [options[:file], header_type]
38
+ end
39
+
40
+ if __FILE__ == $0
41
+ file, header_type = parse_options
42
+ converter = Csv2dokuwikiTab::Converter.new(file, header_type)
43
+ converter.convert
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Csv2dokuwikiTab
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "csv2dokuwiki_tab/version"
4
+
5
+
6
+ ############################
7
+ # csv_to_dokuwiki_tab.rb
8
+ #
9
+ # Read CSV and convert to DokuWiki table format
10
+ # Dokuwiki syntax is described here: https://www.dokuwiki.org/wiki:syntax#tables
11
+ ############################
12
+
13
+ module Csv2dokuwikiTab
14
+ class Error < StandardError; end
15
+ # Your code goes here...
16
+
17
+ require "csv"
18
+
19
+ HEADER_NONE = 0
20
+ HEADER_ROW = 1
21
+ HEADER_COL = 2
22
+ HEADER_BOTH = 3
23
+
24
+ class Converter
25
+ def initialize(file, header_type=1)
26
+ @file = file
27
+ @header_type = header_type
28
+ end
29
+
30
+ def convert
31
+ begin
32
+ CSV.foreach(@file).with_index do |row, idx|
33
+ next if row.all? { |x| x.nil? }
34
+ if idx == 0
35
+ print_header_row(row)
36
+ else
37
+ print_data_row(row)
38
+ end
39
+ end
40
+ rescue Errno::ENOENT
41
+ warn "Error: File not found: #{@file}"
42
+ exit 1
43
+ rescue CSV::MalformedCSVError => e
44
+ warn "Error: Malformed CSV - #{e.message}"
45
+ exit 1
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def print_header_row(row)
52
+ case @header_type
53
+ when HEADER_ROW, HEADER_BOTH
54
+ puts "^" + row.map { |x| " #{x} " }.join("^") + "^"
55
+ else
56
+ puts "|" + row.map { |x| " #{x} " }.join("|") + "|"
57
+ end
58
+ end
59
+
60
+ def print_data_row(row)
61
+ case @header_type
62
+ when HEADER_COL, HEADER_BOTH
63
+ puts "^" + row[0].to_s + "^" + row[1..-1].map { |x| " #{x} " }.join("|") + "|"
64
+ else
65
+ puts "|" + row.map { |x| " #{x} " }.join("|") + "|"
66
+ end
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,4 @@
1
+ module Csv2dokuwikiTab
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csv2dokuwiki_tab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shuji Shigenobu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-09-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem provides a command-line tool to convert CSV files into DokuWiki
14
+ table format.
15
+ email:
16
+ - sshigenobu@gmail.com
17
+ executables:
18
+ - csv2dokuwiki_tab.rb
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - README.md
23
+ - Rakefile
24
+ - examples/example.csv
25
+ - examples/example.tsv
26
+ - exe/csv2dokuwiki_tab.rb
27
+ - lib/csv2dokuwiki_tab.rb
28
+ - lib/csv2dokuwiki_tab/version.rb
29
+ - sig/csv2dokuwiki_tab.rbs
30
+ homepage: https://github.com/sshigenobu/csv2dokuwiki_tab
31
+ licenses: []
32
+ metadata:
33
+ allowed_push_host: https://rubygems.org/
34
+ homepage_uri: https://github.com/sshigenobu/csv2dokuwiki_tab
35
+ source_code_uri: https://github.com/sshigenobu/csv2dokuwiki_tab
36
+ post_install_message:
37
+ rdoc_options: []
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.4.0
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubygems_version: 3.5.9
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Convert CSV to DokuWiki table format
55
+ test_files: []