tbpgr_utils 0.0.45 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -76,6 +76,7 @@ Or install it yourself as:
76
76
  |[TbpgrUtils Object#to_bool](#objectto_bool) |syntax sugar of !!. convert [false, nil] => fasel, other => true. |
77
77
  |[TbpgrUtils String#justify_table](#stringjustify_table) |justify pipe format table string |
78
78
  |[TbpgrUtils String#say](#stringsay) |say string |
79
+ |[TbpgrUtils String#stripe](#stringstripe) |stripe string |
79
80
  |[TbpgrUtils String#surround](#stringsurround) |surround string |
80
81
  |[Templatable module](#templatable) |get result from template + placeholder |
81
82
  |[TemplateMethodable module](#templatemethodable) |for Template Method Pattern |
@@ -1569,6 +1570,38 @@ hyphen case
1569
1570
 
1570
1571
  [back to list](#list)
1571
1572
 
1573
+ ### String#stripe
1574
+ default case
1575
+ ~~~ ruby
1576
+ require 'tbpgr_utils'
1577
+
1578
+ 'hoge'.stripe # => HoGe
1579
+ ~~~
1580
+
1581
+ lower_cap case
1582
+ ~~~ruby
1583
+ require 'tbpgr_utils'
1584
+
1585
+ 'hoge'.stripe :lower_cap # => hOgE
1586
+ ~~~
1587
+
1588
+ empty case
1589
+ ~~~ruby
1590
+ require 'tbpgr_utils'
1591
+
1592
+ ''.stripe # => ''
1593
+ ~~~
1594
+
1595
+ nil case
1596
+ ~~~ruby
1597
+ require 'tbpgr_utils'
1598
+
1599
+ hoge = nil
1600
+ hoge.stripe # => nil
1601
+ ~~~
1602
+
1603
+ [back to list](#list)
1604
+
1572
1605
  ### String#surround
1573
1606
  single line, no option case
1574
1607
 
@@ -1718,6 +1751,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
1718
1751
  https://github.com/tbpgr/tbpgr_utils_snippets
1719
1752
 
1720
1753
  ## History
1754
+ * version 0.0.46 : add String#stripe
1721
1755
  * version 0.0.45 : add String#say
1722
1756
  * version 0.0.44 : add EndERB.apply
1723
1757
  * version 0.0.43 : add Array#together_slice(alias tslice).
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ # String
4
+ class String
5
+ # stripe string.
6
+ #
7
+ # ==== Options
8
+ #
9
+ # * <tt>:lower_cap</tt> - start lower char.
10
+ #
11
+ # ==== Examples
12
+ #
13
+ # default case
14
+ #
15
+ # 'hoge'.stripe # => HoGe
16
+ #
17
+ # lower_cap case
18
+ #
19
+ # 'hoge'.stripe :lower_cap # => hOgE
20
+ #
21
+ # empty case
22
+ #
23
+ # ''.stripe # => ''
24
+ #
25
+ # nil case
26
+ #
27
+ # hoge = nil
28
+ # hoge.stripe # => nil
29
+ #
30
+ def stripe(cap = :upper_cap)
31
+ updowns = %w{upcase downcase}
32
+ index = cap == :lower_cap ? 1 : 0
33
+ chars.reduce([]) do |ret, char|
34
+ ret << char.send(updowns[index % 2])
35
+ index += 1
36
+ ret
37
+ end.join
38
+ end
39
+ end
40
+
41
+ class NilClass
42
+ def stripe
43
+ nil
44
+ end
45
+ end
@@ -1,4 +1,5 @@
1
1
  # encoding: utf-8
2
2
  require 'open_classes/string/justify_table'
3
3
  require 'open_classes/string/say'
4
+ require 'open_classes/string/stripe'
4
5
  require 'open_classes/string/surround'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.45'
5
+ VERSION = '0.0.46'
6
6
  end
@@ -14,7 +14,7 @@ describe String do
14
14
  {
15
15
  case_no: 2,
16
16
  case_title: 'quote case',
17
- input: "hoge",
17
+ input: 'hoge',
18
18
  option: :quote,
19
19
  expected: "'hoge'"
20
20
  },
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'tbpgr_utils'
4
+
5
+ describe String do
6
+ context :surround do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'default case',
11
+ input: 'hoge',
12
+ expected: 'HoGe'
13
+ },
14
+ {
15
+ case_no: 2,
16
+ case_title: 'lower cap case',
17
+ input: 'hoge',
18
+ option: :lower_cap,
19
+ expected: 'hOgE'
20
+ },
21
+ {
22
+ case_no: 3,
23
+ case_title: 'empty case',
24
+ input: '',
25
+ expected: ''
26
+ },
27
+ {
28
+ case_no: 4,
29
+ case_title: 'nil case',
30
+ input: nil,
31
+ expected: nil
32
+ }
33
+ ]
34
+
35
+ cases.each do |c|
36
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
37
+ begin
38
+ case_before c
39
+
40
+ # -- given --
41
+ # nothing
42
+
43
+ # -- when --
44
+ actual = c[:option] ? c[:input].stripe(c[:option]) : c[:input].stripe
45
+
46
+ # -- then --
47
+ expect(actual).to eq(c[:expected])
48
+ ensure
49
+ case_after c
50
+ end
51
+ end
52
+
53
+ def case_before(c)
54
+ # implement each case before
55
+ end
56
+
57
+ def case_after(c)
58
+ # implement each case after
59
+ end
60
+ end
61
+ end
62
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbpgr_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.45
4
+ version: 0.0.46
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-21 00:00:00.000000000 Z
12
+ date: 2014-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &22871184 !ruby/object:Gem::Requirement
16
+ requirement: &26432400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 4.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22871184
24
+ version_requirements: *26432400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &22869852 !ruby/object:Gem::Requirement
27
+ requirement: &26431992 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.3'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *22869852
35
+ version_requirements: *26431992
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &22869444 !ruby/object:Gem::Requirement
38
+ requirement: &26431656 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *22869444
46
+ version_requirements: *26431656
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &22868916 !ruby/object:Gem::Requirement
49
+ requirement: &26431116 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.14.1
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *22868916
57
+ version_requirements: *26431116
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &22868424 !ruby/object:Gem::Requirement
60
+ requirement: &26430816 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.8.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *22868424
68
+ version_requirements: *26430816
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -129,6 +129,7 @@ files:
129
129
  - lib/open_classes/string.rb
130
130
  - lib/open_classes/string/justify_table.rb
131
131
  - lib/open_classes/string/say.rb
132
+ - lib/open_classes/string/stripe.rb
132
133
  - lib/open_classes/string/surround.rb
133
134
  - lib/tbpgr_utils.rb
134
135
  - lib/tbpgr_utils/version.rb
@@ -180,6 +181,7 @@ files:
180
181
  - spec/open_classes/object/to_bool_spec.rb
181
182
  - spec/open_classes/string/justify_table_spec.rb
182
183
  - spec/open_classes/string/say_spec.rb
184
+ - spec/open_classes/string/stripe_spec.rb
183
185
  - spec/open_classes/string/surround_spec.rb
184
186
  - spec/spec_helper.rb
185
187
  - spec/templatable_spec.rb
@@ -255,6 +257,7 @@ test_files:
255
257
  - spec/open_classes/object/to_bool_spec.rb
256
258
  - spec/open_classes/string/justify_table_spec.rb
257
259
  - spec/open_classes/string/say_spec.rb
260
+ - spec/open_classes/string/stripe_spec.rb
258
261
  - spec/open_classes/string/surround_spec.rb
259
262
  - spec/spec_helper.rb
260
263
  - spec/templatable_spec.rb