maketable 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +350 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +175 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +12 -0
- data/doc/.keep +1 -0
- data/docs/_config.yml +1 -0
- data/docs/index.md +37 -0
- data/documents/memo.txt +109 -0
- data/lib/maketable/item.rb +55 -0
- data/lib/maketable/itemx.rb +93 -0
- data/lib/maketable/limitedmarkdown.rb +165 -0
- data/lib/maketable/maketable.rb +229 -0
- data/lib/maketable/order.rb +134 -0
- data/lib/maketable/outputtable.rb +128 -0
- data/lib/maketable/table.rb +9 -0
- data/lib/maketable/tablecolumn.rb +50 -0
- data/lib/maketable/util.rb +63 -0
- data/lib/maketable/utilx.rb +19 -0
- data/lib/maketable/version.rb +5 -0
- data/lib/maketable.rb +27 -0
- data/sig/maketable.rbs +4 -0
- metadata +75 -0
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 ykominami
|
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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 ykominami
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Maketable
|
2
|
+
|
3
|
+
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/maketable`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'maketable'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install maketable
|
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/ykominami/maketable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ykominami/maketable/blob/main/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Maketable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ykominami/maketable/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/doc/.keep
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
""
|
data/docs/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-slate
|
data/docs/index.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
## Welcome to GitHub Pages
|
2
|
+
|
3
|
+
You can use the [editor on GitHub](https://github.com/ykominami/maketable/edit/main/docs/index.md) to maintain and preview the content for your website in Markdown files.
|
4
|
+
|
5
|
+
Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files.
|
6
|
+
|
7
|
+
### Markdown
|
8
|
+
|
9
|
+
Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for
|
10
|
+
|
11
|
+
```markdown
|
12
|
+
Syntax highlighted code block
|
13
|
+
|
14
|
+
# Header 1
|
15
|
+
## Header 2
|
16
|
+
### Header 3
|
17
|
+
|
18
|
+
- Bulleted
|
19
|
+
- List
|
20
|
+
|
21
|
+
1. Numbered
|
22
|
+
2. List
|
23
|
+
|
24
|
+
**Bold** and _Italic_ and `Code` text
|
25
|
+
|
26
|
+
[Link](url) and ![Image](src)
|
27
|
+
```
|
28
|
+
|
29
|
+
For more details see [Basic writing and formatting syntax](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax).
|
30
|
+
|
31
|
+
### Jekyll Themes
|
32
|
+
|
33
|
+
Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/ykominami/maketable/settings/pages). The name of this theme is saved in the Jekyll `_config.yml` configuration file.
|
34
|
+
|
35
|
+
### Support or Contact
|
36
|
+
|
37
|
+
Having trouble with Pages? Check out our [documentation](https://docs.github.com/categories/github-pages-basics/) or [contact support](https://support.github.com/contact) and we’ll help you sort it out.
|
data/documents/memo.txt
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# 参考資料
|
2
|
+
## mkspecで使用しているgem
|
3
|
+
spec.add_development_dependency 'aruba'
|
4
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
5
|
+
spec.add_development_dependency 'coderay', '~> 1.1.1'
|
6
|
+
spec.add_development_dependency 'pre-commit'
|
7
|
+
# spec.add_development_dependency 'pry'
|
8
|
+
spec.add_development_dependency 'pry-byebug'
|
9
|
+
spec.add_development_dependency 'pry-doc'
|
10
|
+
spec.add_development_dependency 'pry-stack_explorer'
|
11
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
12
|
+
spec.add_development_dependency 'rb-readline'
|
13
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
14
|
+
spec.add_development_dependency 'rubocop', '~> 1.7'
|
15
|
+
spec.add_development_dependency 'rubocop-rake'
|
16
|
+
spec.add_development_dependency 'rubocop-rspec'
|
17
|
+
spec.add_development_dependency 'yard'
|
18
|
+
spec.add_dependency 'clitest'
|
19
|
+
spec.add_dependency 'rspec_junit_formatter'
|
20
|
+
spec.add_dependency 'rufo'
|
21
|
+
spec.add_dependency 'erubis', '~> 2.7.0'
|
22
|
+
|
23
|
+
## mkspecのbundle install結果
|
24
|
+
Using rake 13.0.6
|
25
|
+
Using bundler 2.3.7
|
26
|
+
Using diff-lcs 1.5.0
|
27
|
+
Fetching childprocess 4.1.0
|
28
|
+
Fetching contracts 0.17
|
29
|
+
Fetching cucumber-ci-environment 9.1.0
|
30
|
+
Using builder 3.2.4
|
31
|
+
Fetching mime-types-data 3.2022.0105
|
32
|
+
Fetching cucumber-messages 18.0.0
|
33
|
+
Fetching cucumber-tag-expressions 4.1.0
|
34
|
+
Fetching cucumber-cucumber-expressions 15.2.0
|
35
|
+
Fetching multi_test 1.1.0
|
36
|
+
Installing cucumber-tag-expressions 4.1.0
|
37
|
+
Installing multi_test 1.1.0
|
38
|
+
Installing cucumber-ci-environment 9.1.0
|
39
|
+
Installing cucumber-messages 18.0.0
|
40
|
+
Installing cucumber-cucumber-expressions 15.2.0
|
41
|
+
Installing childprocess 4.1.0
|
42
|
+
Installing contracts 0.17
|
43
|
+
Installing mime-types-data 3.2022.0105
|
44
|
+
Using ffi 1.15.5 (x64-mingw-ucrt)
|
45
|
+
Using rspec-support 3.11.0
|
46
|
+
Using thor 1.2.1
|
47
|
+
Using ast 2.4.2
|
48
|
+
Fetching debug_inspector 1.1.0
|
49
|
+
Using byebug 11.1.3
|
50
|
+
Fetching clitest 0.1.1
|
51
|
+
Installing debug_inspector 1.1.0 with native extensions
|
52
|
+
Using coderay 1.1.3
|
53
|
+
Using erubis 2.7.0
|
54
|
+
Using json 2.6.2
|
55
|
+
Using method_source 1.0.0
|
56
|
+
Fetching rufo 0.13.0
|
57
|
+
Installing clitest 0.1.1
|
58
|
+
Using parallel 1.22.1
|
59
|
+
Fetching pluginator 1.5.0
|
60
|
+
Using webrick 1.7.0
|
61
|
+
Using rainbow 3.1.1
|
62
|
+
Fetching rb-readline 0.5.5
|
63
|
+
Using regexp_parser 2.5.0
|
64
|
+
Using rexml 3.2.5
|
65
|
+
Using ruby-progressbar 1.11.0
|
66
|
+
Installing rufo 0.13.0
|
67
|
+
Using unicode-display_width 2.2.0
|
68
|
+
Fetching sys-uname 1.2.2
|
69
|
+
Installing pluginator 1.5.0
|
70
|
+
Installing rb-readline 0.5.5
|
71
|
+
Installing sys-uname 1.2.2
|
72
|
+
Using rspec-expectations 3.11.0
|
73
|
+
Using rspec-core 3.11.0
|
74
|
+
Using rspec-mocks 3.11.1
|
75
|
+
Using parser 3.1.2.0
|
76
|
+
Fetching pry 0.13.1
|
77
|
+
Installing pry 0.13.1
|
78
|
+
Fetching cucumber-gherkin 23.0.1
|
79
|
+
Fetching cucumber-html-formatter 19.2.0
|
80
|
+
Using yard 0.9.28
|
81
|
+
Fetching mime-types 3.4.1
|
82
|
+
Fetching rspec_junit_formatter 0.5.1
|
83
|
+
Installing cucumber-gherkin 23.0.1
|
84
|
+
Installing mime-types 3.4.1
|
85
|
+
Using rspec 3.11.0
|
86
|
+
Using rubocop-ast 1.19.1
|
87
|
+
Fetching pre-commit 0.39.0
|
88
|
+
Installing rspec_junit_formatter 0.5.1
|
89
|
+
Installing cucumber-html-formatter 19.2.0
|
90
|
+
Using rubocop 1.32.0
|
91
|
+
Using rubocop-rake 0.6.0
|
92
|
+
Fetching rubocop-rspec 2.12.1
|
93
|
+
Using mkspec 0.1.0 from source at `.`
|
94
|
+
Installing pre-commit 0.39.0
|
95
|
+
Installing rubocop-rspec 2.12.1
|
96
|
+
Fetching cucumber-core 11.0.0
|
97
|
+
Installing cucumber-core 11.0.0
|
98
|
+
Fetching cucumber 8.0.0
|
99
|
+
Installing cucumber 8.0.0
|
100
|
+
Fetching pry-byebug 3.9.0
|
101
|
+
Fetching pry-doc 1.3.0
|
102
|
+
Installing pry-byebug 3.9.0
|
103
|
+
Fetching aruba 2.1.0
|
104
|
+
Installing aruba 2.1.0
|
105
|
+
Installing pry-doc 1.3.0
|
106
|
+
Fetching binding_of_caller 1.0.0
|
107
|
+
Installing binding_of_caller 1.0.0
|
108
|
+
Fetching pry-stack_explorer 0.6.1
|
109
|
+
Installing pry-stack_explorer 0.6.1
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Maketable
|
4
|
+
class Item
|
5
|
+
attr_reader :desc_str, :date_tail
|
6
|
+
attr_accessor :date_head
|
7
|
+
|
8
|
+
def initialize(desc_str, year_str)
|
9
|
+
@desc_str = desc_str
|
10
|
+
@year_str = year_str
|
11
|
+
@date_head = nil
|
12
|
+
@date_tail = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def output(level)
|
16
|
+
indent = " " * level
|
17
|
+
puts "#{indent}desc_str=#{@desc_str}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def analyze
|
21
|
+
# byebug
|
22
|
+
left, _sep, _right = @desc_str.partition(" ")
|
23
|
+
head, sep, tail = left.partition(",")
|
24
|
+
if sep == ""
|
25
|
+
head, sep, tail = left.partition("-")
|
26
|
+
if sep == ""
|
27
|
+
date_str = %(#{@year_str}/#{left})
|
28
|
+
p "date_str=#{date_str}"
|
29
|
+
datetime_head = DateTime.parse(date_str)
|
30
|
+
@date_head = datetime_head.to_date
|
31
|
+
else
|
32
|
+
datetime_head = DateTime.parse(%(#{@year_str}/#{head}))
|
33
|
+
@date_head = datetime_head.to_date
|
34
|
+
lh, _sep, _rh = head.partition("/")
|
35
|
+
datetime_tail = DateTime.parse(%(#{@year_str}/#{lh}/#{tail}))
|
36
|
+
@date_tail = datetime_tail.to_date
|
37
|
+
end
|
38
|
+
else
|
39
|
+
datetime_head = DateTime.parse(%(#{@year_str}/#{head}))
|
40
|
+
@date_head = datetime_head.to_date
|
41
|
+
lh, _sep, _rh = head.partition("/")
|
42
|
+
datetime_tail = DateTime.parse(%(#{@year_str}/#{lh}/#{tail}))
|
43
|
+
@date_tail = datetime_tail.to_date
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def make_next_month_item
|
48
|
+
dest = Item.new(@desc_str, @year_str)
|
49
|
+
dest.analyze
|
50
|
+
next_month = @date_head.next_month
|
51
|
+
dest.date_head = next_month
|
52
|
+
dest
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Maketable
|
2
|
+
class Itemx
|
3
|
+
attr_reader :parent
|
4
|
+
|
5
|
+
def self.init
|
6
|
+
@root = Itemx.new(:root)
|
7
|
+
@cur_itemx = @root
|
8
|
+
@cur_level = 0
|
9
|
+
@max_level = @cur_level
|
10
|
+
@itemx_by_level = {}
|
11
|
+
@itemx_by_level[@cur_level] = @root
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_root
|
15
|
+
@root
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.show
|
19
|
+
pp @root
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.show_tree
|
23
|
+
@root.show_tree(0)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.reset_under_level(level)
|
27
|
+
(level + 1).upto(@max_level) do |index|
|
28
|
+
@itemx_by_level[index] = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.add(level, name)
|
33
|
+
puts "Itemx.add level=#{level} name=#{name}"
|
34
|
+
if @cur_level < level
|
35
|
+
#p "@cur_level=#{@cur_level} level=#{level}"
|
36
|
+
raise InvalidLevelChangeError if @cur_level != (level - 1)
|
37
|
+
@max_level = level
|
38
|
+
elsif @cur_level > level
|
39
|
+
reset_under_level(level)
|
40
|
+
end
|
41
|
+
current_itemx = @itemx_by_level[level]
|
42
|
+
if current_itemx
|
43
|
+
itemx = Itemx.new(name, current_itemx.parent)
|
44
|
+
if current_itemx.parent
|
45
|
+
current_itemx.parent.add_child(itemx)
|
46
|
+
else
|
47
|
+
raise NoParentItemxError
|
48
|
+
end
|
49
|
+
else
|
50
|
+
parent_level = level - 1
|
51
|
+
if parent_level >= 0
|
52
|
+
parent = @itemx_by_level[parent_level]
|
53
|
+
itemx = Itemx.new(name, parent)
|
54
|
+
if parent
|
55
|
+
parent.add_child(itemx)
|
56
|
+
else
|
57
|
+
puts %!parent_level=#{parent_level}!
|
58
|
+
pp @itemx_by_level
|
59
|
+
raise NoParentItemxError
|
60
|
+
end
|
61
|
+
else
|
62
|
+
raise InvalidParentLevelError
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@itemx_by_level[level] = itemx
|
66
|
+
@cur_level = level
|
67
|
+
end
|
68
|
+
|
69
|
+
def initialize(name = nil, parent = nil)
|
70
|
+
@name = name
|
71
|
+
@children = []
|
72
|
+
@parent = parent
|
73
|
+
end
|
74
|
+
|
75
|
+
def add_name(name)
|
76
|
+
@name = name
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_parent(parent)
|
80
|
+
@parent = parent
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_child(itemx)
|
84
|
+
@children << itemx
|
85
|
+
end
|
86
|
+
|
87
|
+
def show_tree(level)
|
88
|
+
indent = " " * level
|
89
|
+
puts %!#{indent}#{@name}!
|
90
|
+
@children.map{ |x| x.show_tree(level + 1) }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'pathname'
|
3
|
+
module Maketable
|
4
|
+
class LimitedMarkDown
|
5
|
+
class << self
|
6
|
+
def create_from_yaml_file(yaml_file)
|
7
|
+
yaml_file_pn = Pathname.new(yaml_file)
|
8
|
+
yaml_file_parent_pn = yaml_file_pn.parent
|
9
|
+
obj = YAML.load_file(yaml_file_pn)
|
10
|
+
input_file_pn = Pathname.new(obj["input_file"])
|
11
|
+
output_file_pn = Pathname.new(obj["output_file"])
|
12
|
+
|
13
|
+
obj["input_file"] = yaml_file_parent_pn + input_file_pn if !input_file_pn.exist?
|
14
|
+
obj["output_file"] = yaml_file_parent_pn + output_file_pn if !output_file_pn.exist?
|
15
|
+
|
16
|
+
colums_count = obj["columns_count"]
|
17
|
+
table_format = obj["table_format"]
|
18
|
+
headers = obj["headers"]
|
19
|
+
fields = obj["fields"]
|
20
|
+
table_format = obj["table_format"]
|
21
|
+
#format = :markdown
|
22
|
+
fields.map{ |hs|
|
23
|
+
hs["re"] = Regexp.new("^#{hs["name"]}:([^|]*)$")
|
24
|
+
}
|
25
|
+
|
26
|
+
lmd = self.new(obj["input_file"], obj["output_file"])
|
27
|
+
[lmd, obj]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
# 初期化
|
31
|
+
def initialize(infile, outfile)
|
32
|
+
@infile = infile
|
33
|
+
@outfile = outfile
|
34
|
+
@indent = {}
|
35
|
+
@re_heading = Regexp.new("^(#+)(\s*)(.+)")
|
36
|
+
#@re_label = Regexp.new("(.+)\[<(.+)>\]")
|
37
|
+
@re_label = Regexp.new("(.+)<<(.+)>>")
|
38
|
+
@lines = []
|
39
|
+
@table = {}
|
40
|
+
#@max_tag_size = 0
|
41
|
+
@items_count = 0
|
42
|
+
@columns_count = 0
|
43
|
+
@cur_level = 0
|
44
|
+
@labels = []
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
def get_table_width
|
49
|
+
@items_count + @columns_count
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_table_header(labels)
|
53
|
+
line_no = 0
|
54
|
+
@table[line_no] ||= Array.new(get_table_width)
|
55
|
+
labels.each_with_index do |label, index|
|
56
|
+
@table[line_no][@items_count + index] = label
|
57
|
+
end
|
58
|
+
line_no += 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_table_body(lines, next_lineno)
|
62
|
+
lines.each_with_index do |x, index|
|
63
|
+
ind = next_lineno + index
|
64
|
+
@table[ind] ||= Array.new(get_table_width)
|
65
|
+
@table[ind][x[0]] = x[1]
|
66
|
+
x[2,(x.size - 1)].each_with_index do |val, index|
|
67
|
+
@table[ind][@items_count + index] = val
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def make_table
|
73
|
+
width = get_table_width
|
74
|
+
0.upto(@table.keys.size) do |lineno|
|
75
|
+
arr = []
|
76
|
+
0.upto(width) do |index|
|
77
|
+
arr << @table[lineno][index]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_label(level, label)
|
83
|
+
if @cur_level < level
|
84
|
+
raise if (@cur_level + 1) != level
|
85
|
+
@labels[level] = label
|
86
|
+
elsif @cur_level == level
|
87
|
+
@labels[level] = label
|
88
|
+
else
|
89
|
+
(level + 1).upto(@labels.size - 1) do |ind|
|
90
|
+
@labels[ind] = nil
|
91
|
+
end
|
92
|
+
@labels[level] = label
|
93
|
+
end
|
94
|
+
@cur_level = level
|
95
|
+
end
|
96
|
+
|
97
|
+
def get_label
|
98
|
+
#p "@cur_level=#{@cur_level}"
|
99
|
+
if 1 < @cur_level
|
100
|
+
@labels[1,@cur_level]
|
101
|
+
else
|
102
|
+
[]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def output(str)
|
107
|
+
File.open(@outfile, "w"){ |f|
|
108
|
+
f.write(str)
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def md2table(columns_count, header_labels, format, fields)
|
113
|
+
#p fields
|
114
|
+
lines = []
|
115
|
+
raise unless columns_count
|
116
|
+
@columns_count = columns_count
|
117
|
+
max_heading_size = 0
|
118
|
+
arr = File.readlines(@infile)
|
119
|
+
arr.each_with_index do |l, index|
|
120
|
+
next unless l
|
121
|
+
if @re_heading.match(l)
|
122
|
+
heading = Regexp.last_match[1]
|
123
|
+
level = heading.size
|
124
|
+
max_heading_size = level if max_heading_size < level
|
125
|
+
l2 = Regexp.last_match[3]
|
126
|
+
if @re_label.match(l2)
|
127
|
+
content = Regexp.last_match[1]
|
128
|
+
label = Regexp.last_match[2]
|
129
|
+
add_label(level, label)
|
130
|
+
while content.sub!(" ", "")
|
131
|
+
end
|
132
|
+
else
|
133
|
+
content = l2
|
134
|
+
#p "F content=#{content}"
|
135
|
+
end
|
136
|
+
|
137
|
+
data_fields = content.split('||', -1)
|
138
|
+
#p fields
|
139
|
+
|
140
|
+
desc = data_fields.shift
|
141
|
+
status = data_fields.shift
|
142
|
+
arrx = data_fields.zip(fields).map{ |field, x|
|
143
|
+
if field =~ x["re"]
|
144
|
+
x["value"] = Regexp.last_match(1)
|
145
|
+
end
|
146
|
+
x["value"]
|
147
|
+
}
|
148
|
+
|
149
|
+
lx = [level - 1, desc, status, get_label.join("-")].concat(arrx)
|
150
|
+
#puts "lx=#{lx}"
|
151
|
+
lines << lx
|
152
|
+
end
|
153
|
+
end
|
154
|
+
@items_count = max_heading_size
|
155
|
+
next_lineno = create_table_header(header_labels)
|
156
|
+
create_table_body(lines, next_lineno)
|
157
|
+
table = []
|
158
|
+
0.upto(@table.keys.size - 1) do |lineno|
|
159
|
+
l = Utilx.make_table_format(data: @table[lineno], format: format).join("\n")
|
160
|
+
table << l
|
161
|
+
end
|
162
|
+
table.join("\n")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|