Skip to content

Commit

Permalink
add add String#to_tab_heading
Browse files Browse the repository at this point in the history
  • Loading branch information
tbpgr committed Feb 25, 2014
1 parent 9787626 commit 474c172
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 9 deletions.
26 changes: 23 additions & 3 deletions README.md
Expand Up @@ -78,8 +78,9 @@ Or install it yourself as:
|[TbpgrUtils String#say](#stringsay) |say string |
|[TbpgrUtils String#stripe](#stringstripe) |stripe string |
|[TbpgrUtils String#surround](#stringsurround) |surround string |
|[TbpgrUtils String#to_space2_heading](#stringto_space2_heading) |create space2-format heading string with Emmet-like grammar |
|[TbpgrUtils String#to_space4_heading](#stringto_space4_heading) |create space4-format heading string with Emmet-like grammar |
|[TbpgrUtils String#to_space2_heading](#stringto_space2_heading) |create space2-format heading string with Emmet-like grammar |
|[TbpgrUtils String#to_space4_heading](#stringto_space4_heading) |create space4-format heading string with Emmet-like grammar |
|[TbpgrUtils String#to_tab_heading](#stringto_tab_heading) |create tab-format heading string with Emmet-like grammar |
|[Templatable module](#templatable) |get result from template + placeholder |
|[TemplateMethodable module](#templatemethodable) |for Template Method Pattern |

Expand Down Expand Up @@ -1685,7 +1686,6 @@ require 'tbpgr_utils'
\+ case
~~~ruby
require 'tbpgr_utils'

'hoge+hige'.to_space4_heading # => 'hoge\nhige'
~~~

Expand All @@ -1697,6 +1697,25 @@ require 'tbpgr_utils'

[back to list](#list)

### String#to_tab_heading
> case
~~~ruby
require 'tbpgr_utils'
'hoge>hige'.to_tab_heading # => 'hoge\n\thige'
~~~

\+ case
~~~ruby
require 'tbpgr_utils'
'hoge+hige'.to_tab_heading # => 'hoge\nhige'
~~~

^ case
~~~ruby
require 'tbpgr_utils'
'hoge>hige^hege'.to_tab_heading # => 'hoge\n\thige\nhege'
~~~

### Templatable
* include Templatable
* set template by here-document
Expand Down Expand Up @@ -1797,6 +1816,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
https://github.com/tbpgr/tbpgr_utils_snippets

## History
* version 0.0.49 : add String#to_tab_heading
* version 0.0.48 : add String#to_space4_heading
* version 0.0.47 : add String#to_space2_heading
* version 0.0.46 : add String#stripe
Expand Down
1 change: 1 addition & 0 deletions lib/open_classes/string.rb
Expand Up @@ -5,3 +5,4 @@
require 'open_classes/string/surround'
require 'open_classes/string/to_space2_heading'
require 'open_classes/string/to_space4_heading'
require 'open_classes/string/to_tab_heading'
5 changes: 0 additions & 5 deletions lib/open_classes/string/heading_helper.rb
Expand Up @@ -3,11 +3,6 @@

# HeadingHelper
module HeadingHelper
# Space2
SPACE2 = ' '
# Space4
SPACE4 = ' '

private
def to_heading
self_chars = chars
Expand Down
2 changes: 2 additions & 0 deletions lib/open_classes/string/to_space2_heading.rb
Expand Up @@ -4,6 +4,8 @@

class String
include HeadingHelper
# Space2
SPACE2 = ' '

# create heading string with Emmet-like grammar.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/open_classes/string/to_space4_heading.rb
Expand Up @@ -4,6 +4,8 @@

class String
include HeadingHelper
# Space4
SPACE4 = ' '

# create heading string with Emmet-like grammar.
#
Expand Down
35 changes: 35 additions & 0 deletions lib/open_classes/string/to_tab_heading.rb
@@ -0,0 +1,35 @@
# encoding: utf-8
require 'active_support/core_ext/object/inclusion'
require 'open_classes/string/heading_helper'

class String
include HeadingHelper
# Tab
TAB = "\t"

# create heading string with Emmet-like grammar.
#
# ==== Examples
#
# > case
#
# 'hoge>hige'.to_tab_heading # => 'hoge\n\thige'
#
# + case
#
# 'hoge+hige'.to_tab_heading # => 'hoge\nhige'
#
# ^ case
#
# 'hoge>hige^hege'.to_tab_heading # => 'hoge\n\thige\nhege'
#
def to_tab_heading
heading = to_heading
to_tab heading
end

private
def to_tab(heading)
to_head(heading, TAB)
end
end
2 changes: 1 addition & 1 deletion lib/tbpgr_utils/version.rb
Expand Up @@ -2,5 +2,5 @@

# Tbpgr Utilities
module TbpgrUtils
VERSION = '0.0.48'
VERSION = '0.0.49'
end
61 changes: 61 additions & 0 deletions spec/open_classes/string/to_tab_heading_spec.rb
@@ -0,0 +1,61 @@
# encoding: utf-8
require 'spec_helper'
require 'open_classes/string/to_tab_heading'

describe String do
context :to_tab_heading do
cases = [
{
case_no: 1,
case_title: '> case',
input: 'hoge>hige',
expected: "hoge\n\thige",
},
{
case_no: 2,
case_title: '+ case',
input: 'hoge+hige',
expected: "hoge\nhige",
},
{
case_no: 3,
case_title: '^ case',
input: 'hoge>hige^hege',
expected: "hoge\n\thige\nhege",
},
{
case_no: 4,
case_title: 'mix case',
input: 'hoge>hige1+hige2^hege',
expected: "hoge\n\thige1\n\thige2\nhege",
},
]

cases.each do |c|
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
begin
case_before c

# -- given --
# nothing

# -- when --
actual = c[:input].to_tab_heading

# -- then --
expect(actual).to eq(c[:expected])
ensure
case_after c
end
end

def case_before(c)
# implement each case before
end

def case_after(c)
# implement each case after
end
end
end
end

0 comments on commit 474c172

Please sign in to comment.