tbpgr_utils 0.0.44 → 0.0.45

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -66,7 +66,7 @@ Or install it yourself as:
66
66
  |[TbpgrUtils Kernel#print_eval](#kernelprint_eval) |Print code + eval result |
67
67
  |[TbpgrUtils Kernel#puts_eval](#kernelputs_eval) |Puts code + eval result |
68
68
  |[TbpgrUtils Kernel#bulk_puts_eval](#kernelbulk_puts_eval) |Puts each-line-code + eval result |
69
- |[MetasyntacticVariable](#metasyntacticvariable) |META variable, META variable for classes |
69
+ |[MetasyntacticVariable](#metasyntacticvariable) |META variable, META variable for classes |
70
70
  |[TbpgrUtils Module.alias_methods](#modulealias_methods) |create alias methods |
71
71
  |[TbpgrUtils Object#any_of?](#objectany_of) |if self match any one of items, return true |
72
72
  |[TbpgrUtils Object#boolean?](#objectboolean) |data type check for boolean |
@@ -75,6 +75,7 @@ Or install it yourself as:
75
75
  |[TbpgrUtils Object#my_methods](#objectmy_methods) |return public/protected/private self define methods |
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
+ |[TbpgrUtils String#say](#stringsay) |say string |
78
79
  |[TbpgrUtils String#surround](#stringsurround) |surround string |
79
80
  |[Templatable module](#templatable) |get result from template + placeholder |
80
81
  |[TemplateMethodable module](#templatemethodable) |for Template Method Pattern |
@@ -1076,6 +1077,8 @@ for single template script using __END__ and DATA
1076
1077
  sample case
1077
1078
 
1078
1079
  ~~~ruby
1080
+ require "end_erb"
1081
+
1079
1082
  def hoge
1080
1083
  hash = {
1081
1084
  hoge: '@hoge@',
@@ -1538,6 +1541,34 @@ output
1538
1541
 
1539
1542
  [back to list](#list)
1540
1543
 
1544
+ ### String#say
1545
+ default case
1546
+ ~~~ruby
1547
+ 'hoge'.say # => 'hoge'
1548
+ ~~~
1549
+
1550
+ quote case
1551
+ ~~~ruby
1552
+ 'hoge'.say(:quote) # => 'hoge'
1553
+ ~~~
1554
+
1555
+ dquote case
1556
+ ~~~ruby
1557
+ 'hoge'.say(:dquote) # => "hoge"
1558
+ ~~~
1559
+
1560
+ bracket case
1561
+ ~~~ruby
1562
+ 'hoge'.say(:bracket) # => [hoge]
1563
+ ~~~
1564
+
1565
+ hyphen case
1566
+ ~~~ruby
1567
+ 'hoge'.say(:hyphen) # => -hoge-
1568
+ ~~~
1569
+
1570
+ [back to list](#list)
1571
+
1541
1572
  ### String#surround
1542
1573
  single line, no option case
1543
1574
 
@@ -1687,6 +1718,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
1687
1718
  https://github.com/tbpgr/tbpgr_utils_snippets
1688
1719
 
1689
1720
  ## History
1721
+ * version 0.0.45 : add String#say
1690
1722
  * version 0.0.44 : add EndERB.apply
1691
1723
  * version 0.0.43 : add Array#together_slice(alias tslice).
1692
1724
  * version 0.0.42 : add MetasyntacticVariable
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+
3
+ # String
4
+ class String
5
+ # say string.
6
+ #
7
+ # ==== Options
8
+ #
9
+ # * <tt>option</tt> - quote, dquote, bracket, hyphen
10
+ #
11
+ # ==== Examples
12
+ #
13
+ # default case
14
+ #
15
+ # 'hoge'.say # => 'hoge'
16
+ #
17
+ # quote case
18
+ #
19
+ # 'hoge'.say(:quote) # => 'hoge'
20
+ #
21
+ # dquote case
22
+ #
23
+ # 'hoge'.say(:dquote) # => "hoge"
24
+ #
25
+ # bracket case
26
+ #
27
+ # 'hoge'.say(:bracket) # => [hoge]
28
+ #
29
+ # hyphen case
30
+ #
31
+ # 'hoge'.say(:hyphen) # => -hoge-
32
+ #
33
+ def say(option = :quote)
34
+ case option
35
+ when :quote
36
+ "'#{self}'"
37
+ when :dquote
38
+ "\"#{self}\""
39
+ when :bracket
40
+ "[#{self}]"
41
+ when :hyphen
42
+ "-#{self}-"
43
+ else
44
+ fail ArgumentError, "invalid value #{option}"
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,4 @@
1
1
  # encoding: utf-8
2
2
  require 'open_classes/string/justify_table'
3
+ require 'open_classes/string/say'
3
4
  require 'open_classes/string/surround'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.44'
5
+ VERSION = '0.0.45'
6
6
  end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'tbpgr_utils'
4
+
5
+ describe String do
6
+ context :say 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: 'quote case',
17
+ input: "hoge",
18
+ option: :quote,
19
+ expected: "'hoge'"
20
+ },
21
+ {
22
+ case_no: 3,
23
+ case_title: 'dquote case',
24
+ input: 'hoge',
25
+ option: :dquote,
26
+ expected: '"hoge"'
27
+ },
28
+ {
29
+ case_no: 4,
30
+ case_title: 'bracket case',
31
+ input: 'hoge',
32
+ option: :bracket,
33
+ expected: '[hoge]'
34
+ },
35
+ {
36
+ case_no: 5,
37
+ case_title: 'hyphen case',
38
+ input: 'hoge',
39
+ option: :hyphen,
40
+ expected: '-hoge-'
41
+ },
42
+ ]
43
+
44
+ cases.each do |c|
45
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
46
+ begin
47
+ case_before c
48
+
49
+ # -- given --
50
+ # nothing
51
+
52
+ # -- when --
53
+ actual = c[:option] ? c[:input].say(c[:option]) : c[:input].say
54
+
55
+ # -- then --
56
+ expect(actual).to eq(c[:expected])
57
+ ensure
58
+ case_after c
59
+ end
60
+ end
61
+
62
+ def case_before(c)
63
+ # implement each case before
64
+ end
65
+
66
+ def case_after(c)
67
+ # implement each case after
68
+ end
69
+ end
70
+ end
71
+ 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.44
4
+ version: 0.0.45
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-20 00:00:00.000000000 Z
12
+ date: 2014-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &22954584 !ruby/object:Gem::Requirement
16
+ requirement: &22871184 !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: *22954584
24
+ version_requirements: *22871184
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &22954284 !ruby/object:Gem::Requirement
27
+ requirement: &22869852 !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: *22954284
35
+ version_requirements: *22869852
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &22953936 !ruby/object:Gem::Requirement
38
+ requirement: &22869444 !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: *22953936
46
+ version_requirements: *22869444
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &22953516 !ruby/object:Gem::Requirement
49
+ requirement: &22868916 !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: *22953516
57
+ version_requirements: *22868916
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &22953204 !ruby/object:Gem::Requirement
60
+ requirement: &22868424 !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: *22953204
68
+ version_requirements: *22868424
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -128,6 +128,7 @@ files:
128
128
  - lib/open_classes/object/to_bool.rb
129
129
  - lib/open_classes/string.rb
130
130
  - lib/open_classes/string/justify_table.rb
131
+ - lib/open_classes/string/say.rb
131
132
  - lib/open_classes/string/surround.rb
132
133
  - lib/tbpgr_utils.rb
133
134
  - lib/tbpgr_utils/version.rb
@@ -178,6 +179,7 @@ files:
178
179
  - spec/open_classes/object/my_methods_spec.rb
179
180
  - spec/open_classes/object/to_bool_spec.rb
180
181
  - spec/open_classes/string/justify_table_spec.rb
182
+ - spec/open_classes/string/say_spec.rb
181
183
  - spec/open_classes/string/surround_spec.rb
182
184
  - spec/spec_helper.rb
183
185
  - spec/templatable_spec.rb
@@ -252,6 +254,7 @@ test_files:
252
254
  - spec/open_classes/object/my_methods_spec.rb
253
255
  - spec/open_classes/object/to_bool_spec.rb
254
256
  - spec/open_classes/string/justify_table_spec.rb
257
+ - spec/open_classes/string/say_spec.rb
255
258
  - spec/open_classes/string/surround_spec.rb
256
259
  - spec/spec_helper.rb
257
260
  - spec/templatable_spec.rb