gottani 0.0.1
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.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +146 -0
- data/Rakefile +1 -0
- data/gottani.gemspec +27 -0
- data/lib/gottani/version.rb +3 -0
- data/lib/gottani_core.rb +31 -0
- data/lib/indents/base.rb +59 -0
- data/lib/indents/markdown.rb +22 -0
- data/lib/indents/space2.rb +21 -0
- data/lib/indents/space4.rb +21 -0
- data/lib/indents/tab.rb +22 -0
- data/spec/gottani_core_spec.rb +125 -0
- data/spec/indents/tab_spec.rb +188 -0
- data/spec/spec_helper.rb +8 -0
- metadata +122 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 tbpgr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Gottani
|
2
|
+
|
3
|
+
Gottani is coverter for indent-style text.
|
4
|
+
|
5
|
+
## Support type
|
6
|
+
|
7
|
+
* Tab indent
|
8
|
+
* Space2 indent
|
9
|
+
* Space4 indent
|
10
|
+
* Markdown indent
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'gottani'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install gottani
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
### Convert List
|
28
|
+
| type | convert_type key | convert_method_name |
|
29
|
+
|:----------- |:------------ |:------------ |
|
30
|
+
|tab-indent |Gottani::Core.new :tab, text |to_tab |
|
31
|
+
|space2-indent |Gottani::Core.new :space2, text |to_space2 |
|
32
|
+
|space4-indent |Gottani::Core.new :space4, text |to_space4 |
|
33
|
+
|markdown |Gottani::Core.new :markdown, text|to_markdown |
|
34
|
+
|
35
|
+
### tab-indent to space2 indent
|
36
|
+
|
37
|
+
~~~ruby
|
38
|
+
require 'gottani_core'
|
39
|
+
|
40
|
+
text =<<-EOS
|
41
|
+
root
|
42
|
+
child1
|
43
|
+
child1_1
|
44
|
+
child1_1_1
|
45
|
+
child1_1_2
|
46
|
+
child1_2
|
47
|
+
child2
|
48
|
+
child2_1
|
49
|
+
child3
|
50
|
+
EOS
|
51
|
+
|
52
|
+
gottani_core = Gottani::Core.new :tab, text
|
53
|
+
gottani_core.to_space2
|
54
|
+
~~~
|
55
|
+
|
56
|
+
output
|
57
|
+
~~~
|
58
|
+
root
|
59
|
+
child1
|
60
|
+
child1_1
|
61
|
+
child1_1_1
|
62
|
+
child1_1_2
|
63
|
+
child1_2
|
64
|
+
child2
|
65
|
+
child2_1
|
66
|
+
child3
|
67
|
+
~~~
|
68
|
+
|
69
|
+
### space2 to space4 indent
|
70
|
+
|
71
|
+
~~~ruby
|
72
|
+
require 'gottani_core'
|
73
|
+
|
74
|
+
text =<<-EOS
|
75
|
+
root
|
76
|
+
child1
|
77
|
+
child1_1
|
78
|
+
child1_1_1
|
79
|
+
child1_1_2
|
80
|
+
child1_2
|
81
|
+
child2
|
82
|
+
child2_1
|
83
|
+
child3
|
84
|
+
EOS
|
85
|
+
|
86
|
+
gottani_core = Gottani::Core.new :space2, text
|
87
|
+
gottani_core.to_space4
|
88
|
+
~~~
|
89
|
+
|
90
|
+
output
|
91
|
+
~~~
|
92
|
+
root
|
93
|
+
child1
|
94
|
+
child1_1
|
95
|
+
child1_1_1
|
96
|
+
child1_1_2
|
97
|
+
child1_2
|
98
|
+
child2
|
99
|
+
child2_1
|
100
|
+
child3
|
101
|
+
~~~
|
102
|
+
|
103
|
+
### space4 to Markdown indent
|
104
|
+
|
105
|
+
~~~ruby
|
106
|
+
require 'gottani_core'
|
107
|
+
|
108
|
+
text =<<-EOS
|
109
|
+
root
|
110
|
+
child1
|
111
|
+
child1_1
|
112
|
+
child1_1_1
|
113
|
+
child1_1_2
|
114
|
+
child1_2
|
115
|
+
child2
|
116
|
+
child2_1
|
117
|
+
child3
|
118
|
+
EOS
|
119
|
+
|
120
|
+
gottani_core = Gottani::Core.new :space4, text
|
121
|
+
gottani_core.to_markdown
|
122
|
+
~~~
|
123
|
+
|
124
|
+
output
|
125
|
+
~~~
|
126
|
+
# root
|
127
|
+
## child1
|
128
|
+
### child1_1
|
129
|
+
#### child1_1_1
|
130
|
+
#### child1_1_2
|
131
|
+
### child1_2
|
132
|
+
## child2
|
133
|
+
### child2_1
|
134
|
+
## child3
|
135
|
+
~~~
|
136
|
+
|
137
|
+
## History
|
138
|
+
* version 0.0.1 : first release.
|
139
|
+
|
140
|
+
## Contributing
|
141
|
+
|
142
|
+
1. Fork it
|
143
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
144
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
145
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
146
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/gottani.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gottani/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gottani"
|
8
|
+
spec.version = Gottani::VERSION
|
9
|
+
spec.authors = ["tbpgr"]
|
10
|
+
spec.email = ["tbpgr@tbpgr.jp"]
|
11
|
+
spec.description = %q{Gottani is coverter for indent-style text.}
|
12
|
+
spec.summary = %q{Gottani is coverter for indent-style text.}
|
13
|
+
spec.homepage = "https://github.com/tbpgr/gottani"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "activesupport", "~> 4.0.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 2.14.1"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.8.2"
|
27
|
+
end
|
data/lib/gottani_core.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'indents/tab'
|
4
|
+
require 'indents/space2'
|
5
|
+
require 'indents/space4'
|
6
|
+
require 'indents/markdown'
|
7
|
+
|
8
|
+
module Gottani
|
9
|
+
class Core
|
10
|
+
attr_reader :type, :common
|
11
|
+
FORMAT = {
|
12
|
+
tab: Gottani::Tab,
|
13
|
+
space2: Gottani::Space2,
|
14
|
+
space4: Gottani::Space4,
|
15
|
+
markdown: Gottani::Markdown,
|
16
|
+
}
|
17
|
+
|
18
|
+
def initialize(type, base)
|
19
|
+
instance = FORMAT[type].new
|
20
|
+
@common = instance.send "#{type.to_s}_to_common", base
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(method_name, *args, &block)
|
24
|
+
method_name.match /^to_(.*)$/
|
25
|
+
super unless Regexp.last_match[1]
|
26
|
+
instance = FORMAT[Regexp.last_match[1].to_sym].new
|
27
|
+
return instance.send("to_#{Regexp.last_match[1]}", @common) if instance
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/indents/base.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
module Gottani
|
5
|
+
module Base
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
attr_accessor :indent_char, :separator
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def define_to_common(base)
|
11
|
+
define_method "#{base.to_s}_to_common".to_sym do |text|
|
12
|
+
to_common text, indent_char, separator
|
13
|
+
end
|
14
|
+
alias_method "to_#{base.to_s}".to_sym, :to_indent_text
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@indent_char = get_indent_char
|
20
|
+
@zero_start = zero_start?
|
21
|
+
@separator = get_separator
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_common(text, indent_char, separator = '')
|
25
|
+
ret = []
|
26
|
+
text.each_line.with_index do |line, index|
|
27
|
+
chopped_line = line.chop
|
28
|
+
line_hash = {}
|
29
|
+
level = zero_start? ? indent_level(chopped_line) - 1 : indent_level(chopped_line)
|
30
|
+
line_hash[:level] = level
|
31
|
+
line_hash[:value] = indentless_line(chopped_line)
|
32
|
+
line_hash[:value].gsub!(/^#{@separator}/, '') unless @separator.nil?
|
33
|
+
ret << line_hash
|
34
|
+
end
|
35
|
+
ret
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_indent_text(common)
|
39
|
+
common.reduce([]) do |ret, line|
|
40
|
+
level = zero_start? ? line[:level] + 1 : line[:level]
|
41
|
+
indent = @indent_char * level
|
42
|
+
indent = indent + @separator unless @separator.nil?
|
43
|
+
ret << "#{indent}#{line[:value]}"
|
44
|
+
end.join("\n") + "\n"
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def indent_level(line)
|
50
|
+
prefix_indents = line.scan(/^#{@indent_char}*/).first
|
51
|
+
prefix_indents = prefix_indents.nil? ? '' : prefix_indents
|
52
|
+
prefix_indents.scan(@indent_char).size
|
53
|
+
end
|
54
|
+
|
55
|
+
def indentless_line(chopped_line)
|
56
|
+
chopped_line.gsub(/^#{@indent_char}*/, '')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'indents/base'
|
3
|
+
|
4
|
+
module Gottani
|
5
|
+
class Markdown
|
6
|
+
include Base
|
7
|
+
|
8
|
+
define_to_common :markdown
|
9
|
+
|
10
|
+
def get_indent_char
|
11
|
+
'#'
|
12
|
+
end
|
13
|
+
|
14
|
+
def zero_start?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_separator
|
19
|
+
' '
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'indents/base'
|
3
|
+
|
4
|
+
module Gottani
|
5
|
+
class Space2
|
6
|
+
include Base
|
7
|
+
define_to_common :space2
|
8
|
+
|
9
|
+
def get_indent_char
|
10
|
+
' '
|
11
|
+
end
|
12
|
+
|
13
|
+
def zero_start?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_separator
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'indents/base'
|
3
|
+
|
4
|
+
module Gottani
|
5
|
+
class Space4
|
6
|
+
include Base
|
7
|
+
define_to_common :space4
|
8
|
+
|
9
|
+
def get_indent_char
|
10
|
+
' '
|
11
|
+
end
|
12
|
+
|
13
|
+
def zero_start?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_separator
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/indents/tab.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'indents/base'
|
3
|
+
|
4
|
+
module Gottani
|
5
|
+
class Tab
|
6
|
+
include Base
|
7
|
+
|
8
|
+
define_to_common :tab
|
9
|
+
|
10
|
+
def get_indent_char
|
11
|
+
"\t"
|
12
|
+
end
|
13
|
+
|
14
|
+
def zero_start?
|
15
|
+
false
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_separator
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'gottani_core'
|
4
|
+
|
5
|
+
describe Gottani::Core do
|
6
|
+
context :to_tab do
|
7
|
+
TAB = <<-EOS
|
8
|
+
root
|
9
|
+
child1
|
10
|
+
child1_1
|
11
|
+
child1_1_1
|
12
|
+
child1_1_2
|
13
|
+
child1_2
|
14
|
+
child2
|
15
|
+
child2_1
|
16
|
+
child3
|
17
|
+
EOS
|
18
|
+
|
19
|
+
SPACE2 = <<-EOS
|
20
|
+
root
|
21
|
+
child1
|
22
|
+
child1_1
|
23
|
+
child1_1_1
|
24
|
+
child1_1_2
|
25
|
+
child1_2
|
26
|
+
child2
|
27
|
+
child2_1
|
28
|
+
child3
|
29
|
+
EOS
|
30
|
+
|
31
|
+
SPACE4 = <<-EOS
|
32
|
+
root
|
33
|
+
child1
|
34
|
+
child1_1
|
35
|
+
child1_1_1
|
36
|
+
child1_1_2
|
37
|
+
child1_2
|
38
|
+
child2
|
39
|
+
child2_1
|
40
|
+
child3
|
41
|
+
EOS
|
42
|
+
|
43
|
+
MARKDOWN = <<-EOS
|
44
|
+
# root
|
45
|
+
## child1
|
46
|
+
### child1_1
|
47
|
+
#### child1_1_1
|
48
|
+
#### child1_1_2
|
49
|
+
### child1_2
|
50
|
+
## child2
|
51
|
+
### child2_1
|
52
|
+
## child3
|
53
|
+
EOS
|
54
|
+
|
55
|
+
cases = [
|
56
|
+
{
|
57
|
+
case_no: 1,
|
58
|
+
case_title: 'space2 to tab case',
|
59
|
+
type: :space2,
|
60
|
+
input: SPACE2,
|
61
|
+
method_name: :to_tab,
|
62
|
+
expected: TAB
|
63
|
+
},
|
64
|
+
{
|
65
|
+
case_no: 2,
|
66
|
+
case_title: 'tab to space2 case',
|
67
|
+
type: :tab,
|
68
|
+
input: TAB,
|
69
|
+
method_name: :to_space2,
|
70
|
+
expected: SPACE2
|
71
|
+
},
|
72
|
+
{
|
73
|
+
case_no: 3,
|
74
|
+
case_title: 'tab to space4 case',
|
75
|
+
type: :tab,
|
76
|
+
input: TAB,
|
77
|
+
method_name: :to_space4,
|
78
|
+
expected: SPACE4
|
79
|
+
},
|
80
|
+
{
|
81
|
+
case_no: 4,
|
82
|
+
case_title: 'tab to markdown case',
|
83
|
+
type: :tab,
|
84
|
+
input: TAB,
|
85
|
+
method_name: :to_markdown,
|
86
|
+
expected: MARKDOWN
|
87
|
+
},
|
88
|
+
{
|
89
|
+
case_no: 5,
|
90
|
+
case_title: 'markdown to tab case',
|
91
|
+
type: :markdown,
|
92
|
+
input: MARKDOWN,
|
93
|
+
method_name: :to_tab,
|
94
|
+
expected: TAB
|
95
|
+
},
|
96
|
+
]
|
97
|
+
|
98
|
+
cases.each do |c|
|
99
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
100
|
+
begin
|
101
|
+
case_before c
|
102
|
+
|
103
|
+
# -- given --
|
104
|
+
gottani_core = Gottani::Core.new c[:type], c[:input]
|
105
|
+
|
106
|
+
# -- when --
|
107
|
+
actual = gottani_core.send c[:method_name]
|
108
|
+
|
109
|
+
# -- then --
|
110
|
+
expect(actual).to eq(c[:expected])
|
111
|
+
ensure
|
112
|
+
case_after c
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def case_before(c)
|
117
|
+
# implement each case before
|
118
|
+
end
|
119
|
+
|
120
|
+
def case_after(c)
|
121
|
+
# implement each case after
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'indents/tab'
|
4
|
+
|
5
|
+
describe Gottani::Tab do
|
6
|
+
class ConcreteTab
|
7
|
+
attr_reader :text, :common
|
8
|
+
|
9
|
+
def initialize(text)
|
10
|
+
@text = text
|
11
|
+
@common = Gottani::Tab.new.tab_to_common text
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context :tab_to_common do
|
16
|
+
CASE1_INPUT = <<-EOS
|
17
|
+
root
|
18
|
+
child1
|
19
|
+
child1_1
|
20
|
+
child1_1_1
|
21
|
+
child1_1_2
|
22
|
+
child1_2
|
23
|
+
child2
|
24
|
+
child2_1
|
25
|
+
child3
|
26
|
+
EOS
|
27
|
+
cases = [
|
28
|
+
{
|
29
|
+
case_no: 1,
|
30
|
+
case_title: 'valid case',
|
31
|
+
klass: ConcreteTab,
|
32
|
+
input: CASE1_INPUT,
|
33
|
+
expected: [
|
34
|
+
{
|
35
|
+
level: 0,
|
36
|
+
value: 'root'
|
37
|
+
},
|
38
|
+
{
|
39
|
+
level: 1,
|
40
|
+
value: 'child1'
|
41
|
+
},
|
42
|
+
{
|
43
|
+
level: 2,
|
44
|
+
value: 'child1_1'
|
45
|
+
},
|
46
|
+
{
|
47
|
+
level: 3,
|
48
|
+
value: 'child1_1_1'
|
49
|
+
},
|
50
|
+
{
|
51
|
+
level: 3,
|
52
|
+
value: 'child1_1_2'
|
53
|
+
},
|
54
|
+
{
|
55
|
+
level: 2,
|
56
|
+
value: 'child1_2'
|
57
|
+
},
|
58
|
+
{
|
59
|
+
level: 1,
|
60
|
+
value: 'child2'
|
61
|
+
},
|
62
|
+
{
|
63
|
+
level: 2,
|
64
|
+
value: 'child2_1'
|
65
|
+
},
|
66
|
+
{
|
67
|
+
level: 1,
|
68
|
+
value: 'child3'
|
69
|
+
},
|
70
|
+
],
|
71
|
+
},
|
72
|
+
]
|
73
|
+
|
74
|
+
cases.each do |c|
|
75
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
76
|
+
begin
|
77
|
+
case_before c
|
78
|
+
|
79
|
+
# -- given --
|
80
|
+
tab = c[:klass].new c[:input]
|
81
|
+
|
82
|
+
# -- when --
|
83
|
+
actual = tab.common
|
84
|
+
|
85
|
+
# -- then --
|
86
|
+
expect(actual).to eq(c[:expected])
|
87
|
+
ensure
|
88
|
+
case_after c
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def case_before(c)
|
93
|
+
# implement each case before
|
94
|
+
end
|
95
|
+
|
96
|
+
def case_after(c)
|
97
|
+
# implement each case after
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context :to_tab do
|
103
|
+
EXPECTED_TABTREE_CASE1 = <<-EOS
|
104
|
+
root
|
105
|
+
child1
|
106
|
+
child1_1
|
107
|
+
child1_1_1
|
108
|
+
child1_1_2
|
109
|
+
child1_2
|
110
|
+
child2
|
111
|
+
child2_1
|
112
|
+
child3
|
113
|
+
EOS
|
114
|
+
cases = [
|
115
|
+
{
|
116
|
+
case_no: 1,
|
117
|
+
case_title: 'valid case',
|
118
|
+
input: [
|
119
|
+
{
|
120
|
+
level: 0,
|
121
|
+
value: 'root'
|
122
|
+
},
|
123
|
+
{
|
124
|
+
level: 1,
|
125
|
+
value: 'child1'
|
126
|
+
},
|
127
|
+
{
|
128
|
+
level: 2,
|
129
|
+
value: 'child1_1'
|
130
|
+
},
|
131
|
+
{
|
132
|
+
level: 3,
|
133
|
+
value: 'child1_1_1'
|
134
|
+
},
|
135
|
+
{
|
136
|
+
level: 3,
|
137
|
+
value: 'child1_1_2'
|
138
|
+
},
|
139
|
+
{
|
140
|
+
level: 2,
|
141
|
+
value: 'child1_2'
|
142
|
+
},
|
143
|
+
{
|
144
|
+
level: 1,
|
145
|
+
value: 'child2'
|
146
|
+
},
|
147
|
+
{
|
148
|
+
level: 2,
|
149
|
+
value: 'child2_1'
|
150
|
+
},
|
151
|
+
{
|
152
|
+
level: 1,
|
153
|
+
value: 'child3'
|
154
|
+
},
|
155
|
+
],
|
156
|
+
expected: EXPECTED_TABTREE_CASE1
|
157
|
+
},
|
158
|
+
]
|
159
|
+
|
160
|
+
cases.each do |c|
|
161
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
162
|
+
begin
|
163
|
+
case_before c
|
164
|
+
|
165
|
+
# -- given --
|
166
|
+
tab = Gottani::Tab.new
|
167
|
+
|
168
|
+
# -- when --
|
169
|
+
common = Gottani::Tab.new.tab_to_common c[:expected]
|
170
|
+
actual = tab.to_tab common
|
171
|
+
|
172
|
+
# -- then --
|
173
|
+
expect(actual).to eq(c[:expected])
|
174
|
+
ensure
|
175
|
+
case_after c
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
def case_before(c)
|
180
|
+
# implement each case before
|
181
|
+
end
|
182
|
+
|
183
|
+
def case_after(c)
|
184
|
+
# implement each case after
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gottani
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tbpgr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: &30370980 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.0.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *30370980
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bundler
|
27
|
+
requirement: &30370680 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '1.3'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *30370680
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &30370452 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *30370452
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: &30370128 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.1
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *30370128
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: &30369828 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ~>
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 0.8.2
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *30369828
|
69
|
+
description: Gottani is coverter for indent-style text.
|
70
|
+
email:
|
71
|
+
- tbpgr@tbpgr.jp
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- gottani.gemspec
|
83
|
+
- lib/gottani/version.rb
|
84
|
+
- lib/gottani_core.rb
|
85
|
+
- lib/indents/base.rb
|
86
|
+
- lib/indents/markdown.rb
|
87
|
+
- lib/indents/space2.rb
|
88
|
+
- lib/indents/space4.rb
|
89
|
+
- lib/indents/tab.rb
|
90
|
+
- spec/gottani_core_spec.rb
|
91
|
+
- spec/indents/tab_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: https://github.com/tbpgr/gottani
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 1.8.11
|
115
|
+
signing_key:
|
116
|
+
specification_version: 3
|
117
|
+
summary: Gottani is coverter for indent-style text.
|
118
|
+
test_files:
|
119
|
+
- spec/gottani_core_spec.rb
|
120
|
+
- spec/indents/tab_spec.rb
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
has_rdoc:
|