tbpgr_utils 0.0.62 → 0.0.63

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -58,12 +58,13 @@ Or install it yourself as:
58
58
  |[AttributesInitializable::ClassMethods.attr_writer init](#attributesinitializableclassmethodsattr_writer_init) |generate attr_writer + initializer |
59
59
  |[EndERB.apply](#enderbapply) |for single template script using __END__ and DATA |
60
60
  |[EvalHelper Object](#evalhelper-object) |enable to use EvalHelper in Object |
61
+ |[EvalHelper#each_brace_code](#evalhelpereach_brace_code) |create each brace single line code, for eval |
61
62
  |[EvalHelper#if_code](#evalhelperif_code) |create if strings, for eval |
62
63
  |[EvalHelper#if_code_after](#evalhelperif_code_after) |create after-if strings, for eval |
63
64
  |[EvalHelper#require_code](#evalhelperrequire_code) |create require strings, for eval |
64
65
  |[EvalHelper#require_relative_code](#evalhelperrequire_relative_code) |create require_relative strings, for eval |
65
66
  |[EvalHelper#set_variable_code](#evalhelperset_variable_code) |create set_variable_code strings, for eval |
66
- |[EvalHelper#set_variables_code](#evalhelperset_variables_code) |create set_variables_code strings, for eval |
67
+ |[EvalHelper#set_variables_code](#evalhelperset_variables_code) |create set_variables_code strings, for eval |
67
68
  |[EvalHelper#times_code](#evalhelpertimes_code) |create times_code strings, for eval |
68
69
  |[EvalHelper#ternary_operator](#evalhelperternary_operator) |create ternary operator strings, for eval |
69
70
  |[EvalHelper#unless_code](#evalhelperunless_code) |create unless strings, for eval |
@@ -85,6 +86,8 @@ Or install it yourself as:
85
86
  |[TbpgrUtils Object#unless_guard](#objectunless_guard) |data type check for unless_guard |
86
87
  |[TbpgrUtils Object#my_methods](#objectmy_methods) |return public/protected/private self define methods |
87
88
  |[TbpgrUtils Object#to_bool](#objectto_bool) |syntax sugar of !!. convert [false, nil] => fasel, other => true. |
89
+ |[TbpgrUtils String#comma_to_a](#stringcomma_to_a) |comma-format string to array |
90
+ |[TbpgrUtils String#hyphen_to_a](#stringhyphen_to_a) |hyphen-format string to array |
88
91
  |[TbpgrUtils String#justify_table](#stringjustify_table) |justify pipe format table string |
89
92
  |[TbpgrUtils String#say](#stringsay) |say string |
90
93
  |[TbpgrUtils String#stripe](#stringstripe) |stripe string |
@@ -1377,11 +1380,32 @@ require_code("hoge") # => 'require "hoge"'
1377
1380
 
1378
1381
  [back to list](#list)
1379
1382
 
1383
+ ### EvalHelper#each_brace_code
1384
+ ~~~ruby
1385
+ require 'eval_helper'
1386
+ class EvalHelperEacjBraceTest
1387
+ include EvalHelper
1388
+
1389
+ def hoge(hash)
1390
+ each_brace_code(hash[:target], hash[:proc])
1391
+ end
1392
+ end
1393
+
1394
+ hash = {
1395
+ target: '[:a, :b]',
1396
+ proc: 'puts v',
1397
+ }
1398
+ EvalHelperEacjBraceTest.new.hoge(hash) # => return '[:a, :b].each { |v|puts v }'
1399
+ ~~~
1400
+
1401
+ [back to list](#list)
1402
+
1380
1403
  ### EvalHelper#if_code
1381
1404
 
1382
1405
  if case
1383
1406
 
1384
1407
  ~~~ruby
1408
+ require 'eval_helper'
1385
1409
  class EvalHelperTest
1386
1410
  include EvalHelper
1387
1411
 
@@ -1404,6 +1428,7 @@ EvalHelperTest.new.hoge(hash) # => return true
1404
1428
  else case
1405
1429
 
1406
1430
  ~~~ruby
1431
+ require 'eval_helper'
1407
1432
  class EvalHelperTest
1408
1433
  include EvalHelper
1409
1434
 
@@ -1482,6 +1507,7 @@ EvalHelperTest.new.hoge(hash) # => return 'default'
1482
1507
  single require case
1483
1508
 
1484
1509
  ~~~ruby
1510
+ require 'eval_helper'
1485
1511
  class EvalHelperRequireTest
1486
1512
  include EvalHelper
1487
1513
 
@@ -1497,6 +1523,7 @@ EvalHelperRequireTest.new.hoge(args) # => return "require 'tbpgr_utils'\n"
1497
1523
  muiti require case
1498
1524
 
1499
1525
  ~~~ruby
1526
+ require 'eval_helper'
1500
1527
  class EvalHelperRequireTest
1501
1528
  include EvalHelper
1502
1529
 
@@ -1515,6 +1542,7 @@ EvalHelperRequireTest.new.hoge(args) # => return "require 'tbpgr_utils'\nrequire
1515
1542
  single require_relative case
1516
1543
 
1517
1544
  ~~~ruby
1545
+ require 'eval_helper'
1518
1546
  class EvalHelperRequireRelativeTest
1519
1547
  include EvalHelper
1520
1548
 
@@ -1530,6 +1558,7 @@ EvalHelperRequireRelativeTest.new.hoge(args) # => return "require_relative 'tbpg
1530
1558
  muiti require_relative case
1531
1559
 
1532
1560
  ~~~ruby
1561
+ require 'eval_helper'
1533
1562
  class EvalHelperRequireRelativeTest
1534
1563
  include EvalHelper
1535
1564
 
@@ -1745,6 +1774,7 @@ EvalHelperTernaryTest.new.hoge(hash) # => return 'false'
1745
1774
  unless case
1746
1775
 
1747
1776
  ~~~ruby
1777
+ require 'eval_helper'
1748
1778
  class EvalHelperTest
1749
1779
  include EvalHelper
1750
1780
 
@@ -1767,6 +1797,7 @@ EvalHelperTest.new.hoge(hash) # => return true
1767
1797
  else case
1768
1798
 
1769
1799
  ~~~ruby
1800
+ require 'eval_helper'
1770
1801
  class EvalHelperTest
1771
1802
  include EvalHelper
1772
1803
 
@@ -2010,6 +2041,40 @@ p 0.to_bool # => true
2010
2041
 
2011
2042
  [back to list](#list)
2012
2043
 
2044
+ ### String#comma_to_a
2045
+ space commma case
2046
+
2047
+ ~~~ruby
2048
+ require 'tbpgr_utils'
2049
+ '1, 5, 9'.comma_to_a # => ["1", "5", "9"]
2050
+ ~~~
2051
+
2052
+ commma case
2053
+
2054
+ ~~~ruby
2055
+ require 'tbpgr_utils'
2056
+ '1,5,9'.comma_to_a # => ["1", "5", "9"]
2057
+ ~~~
2058
+
2059
+ [back to list](#list)
2060
+
2061
+ ### String#hyphen_to_a
2062
+ number case
2063
+
2064
+ ~~~ruby
2065
+ require 'tbpgr_utils'
2066
+ '1-5'.hyphen_to_a # => [1, 2, 3, 4, 5]
2067
+ ~~~
2068
+
2069
+ alphabet case
2070
+
2071
+ ~~~ruby
2072
+ require 'tbpgr_utils'
2073
+ '"a"-"e"'.hyphen_to_a # => ['a', 'b', 'c', 'd', 'e']
2074
+ ~~~
2075
+
2076
+ [back to list](#list)
2077
+
2013
2078
  ### String#justify_table
2014
2079
  ~~~ruby
2015
2080
  require 'tbpgr_utils'
@@ -2348,6 +2413,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
2348
2413
  https://github.com/tbpgr/tbpgr_utils_snippets
2349
2414
 
2350
2415
  ## History
2416
+ * version 0.0.63 : add EvalHelper#each_brace_code, String#hyphen_to_a, String#commma_to_a
2351
2417
  * version 0.0.62 : add EvalHelper#set_variables_code
2352
2418
  * version 0.0.61 : add EvalHelper#set_variable_code
2353
2419
  * version 0.0.60 : add EvalHelper#times_code
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module EvalHelper
4
+ # create each brace single line code, for eval
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # class EvalHelperEacjBraceTest
9
+ # include EvalHelper
10
+ #
11
+ # def hoge(hash)
12
+ # each_brace_code(hash[:target], hash[:proc])
13
+ # end
14
+ # end
15
+ #
16
+ # hash = {
17
+ # target: '[:a, :b]',
18
+ # proc: 'puts v',
19
+ # }
20
+ # EvalHelperEacjBraceTest.new.hoge(hash) # => return '[:a, :b].each { |v|puts v }'
21
+ #
22
+ def each_brace_code(target, proc)
23
+ "#{target}.each { |v|#{proc} }"
24
+ end
25
+ end
data/lib/eval_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module EvalHelper
4
+ require 'eval_helper/each_brace_code'
4
5
  require 'eval_helper/if_code'
5
6
  require 'eval_helper/if_code_after'
6
7
  require 'eval_helper/require_code'
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ # String
4
+ class String
5
+ # comma-format string to array.
6
+ #
7
+ # ==== Examples
8
+ #
9
+ # space commma case
10
+ #
11
+ # '1, 5, 9'.comma_to_a # => ["1", "5", "9"]
12
+ #
13
+ # commma case
14
+ #
15
+ # '1,5,9'.comma_to_a # => ["1", "5", "9"]
16
+ #
17
+ def comma_to_a
18
+ return self unless self.include? ','
19
+ gsub(' ', '').split(',')
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ # String
4
+ class String
5
+ # hyphen-format string to array.
6
+ #
7
+ # ==== Examples
8
+ #
9
+ # number case
10
+ #
11
+ # '1-5'.hyphen_to_a # => [1, 2, 3, 4, 5]
12
+ #
13
+ # alphabet case
14
+ #
15
+ # '"a"-"e"'.hyphen_to_a # => ['a', 'b', 'c', 'd', 'e']
16
+ #
17
+ def hyphen_to_a
18
+ return self unless self.include? '-'
19
+ return self unless count('-') == 1
20
+ eval "[*#{gsub('-', '..')}]", binding
21
+ end
22
+ end
@@ -1,4 +1,6 @@
1
1
  # encoding: utf-8
2
+ require 'open_classes/string/comma_to_a'
3
+ require 'open_classes/string/hyphen_to_a'
2
4
  require 'open_classes/string/justify_table'
3
5
  require 'open_classes/string/say'
4
6
  require 'open_classes/string/stripe'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.62'
5
+ VERSION = '0.0.63'
6
6
  end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'eval_helper'
4
+
5
+ describe 'EvalHelper' do
6
+ context :each_brace_code do
7
+ class EvalHelperEacjBraceTest
8
+ include EvalHelper
9
+
10
+ def hoge(hash)
11
+ each_brace_code(hash[:target], hash[:proc])
12
+ end
13
+ end
14
+ cases = [
15
+ {
16
+ case_no: 1,
17
+ case_title: 'unless case',
18
+ target: '[:a, :b]',
19
+ proc: 'puts v',
20
+ expected: '[:a, :b].each { |v|puts v }',
21
+ },
22
+ ]
23
+
24
+ cases.each do |c|
25
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
26
+ begin
27
+ case_before c
28
+
29
+ # -- given --
30
+ eval_helper = EvalHelperEacjBraceTest.new
31
+
32
+ # -- when --
33
+ actual = eval_helper.hoge(c)
34
+
35
+ # -- then --
36
+ expect(actual).to eq(c[:expected])
37
+ ensure
38
+ case_after c
39
+ end
40
+ end
41
+
42
+ def case_before(c)
43
+ # implement each case before
44
+ end
45
+
46
+ def case_after(c)
47
+ # implement each case after
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'tbpgr_utils'
4
+
5
+ describe String do
6
+ context :comma_to_a do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'space commma case',
11
+ input: '1, 5, 9',
12
+ expected: ['1', '5', '9']
13
+ },
14
+ {
15
+ case_no: 2,
16
+ case_title: 'commma case',
17
+ input: '1,5,9',
18
+ expected: ['1', '5', '9']
19
+ },
20
+ ]
21
+
22
+ cases.each do |c|
23
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
24
+ begin
25
+ case_before c
26
+
27
+ # -- given --
28
+ # nothing
29
+
30
+ # -- when --
31
+ actual = c[:input].comma_to_a
32
+
33
+ # -- then --
34
+ expect(actual).to eq(c[:expected])
35
+ ensure
36
+ case_after c
37
+ end
38
+ end
39
+
40
+ def case_before(c)
41
+ # implement each case before
42
+ end
43
+
44
+ def case_after(c)
45
+ # implement each case after
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'tbpgr_utils'
4
+
5
+ describe String do
6
+ context :hyphen_to_a do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'number case',
11
+ input: '1-5',
12
+ expected: [1, 2, 3, 4, 5]
13
+ },
14
+ {
15
+ case_no: 2,
16
+ case_title: 'alphabet case',
17
+ input: '"a"-"e"',
18
+ expected: ['a', 'b', 'c', 'd', 'e']
19
+ },
20
+ ]
21
+
22
+ cases.each do |c|
23
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
24
+ begin
25
+ case_before c
26
+
27
+ # -- given --
28
+ # nothing
29
+
30
+ # -- when --
31
+ actual = c[:input].hyphen_to_a
32
+
33
+ # -- then --
34
+ expect(actual).to eq(c[:expected])
35
+ ensure
36
+ case_after c
37
+ end
38
+ end
39
+
40
+ def case_before(c)
41
+ # implement each case before
42
+ end
43
+
44
+ def case_after(c)
45
+ # implement each case after
46
+ end
47
+ end
48
+ end
49
+ 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.62
4
+ version: 0.0.63
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-03-10 00:00:00.000000000 Z
12
+ date: 2014-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &26240724 !ruby/object:Gem::Requirement
16
+ requirement: &25891968 !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: *26240724
24
+ version_requirements: *25891968
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &26240196 !ruby/object:Gem::Requirement
27
+ requirement: &25891680 !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: *26240196
35
+ version_requirements: *25891680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &26239788 !ruby/object:Gem::Requirement
38
+ requirement: &25891452 !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: *26239788
46
+ version_requirements: *25891452
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &26239392 !ruby/object:Gem::Requirement
49
+ requirement: &25891128 !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: *26239392
57
+ version_requirements: *25891128
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &26238984 !ruby/object:Gem::Requirement
60
+ requirement: &25890828 !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: *26238984
68
+ version_requirements: *25890828
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -86,6 +86,7 @@ files:
86
86
  - lib/attributes_initializable.rb
87
87
  - lib/end_erb.rb
88
88
  - lib/eval_helper.rb
89
+ - lib/eval_helper/each_brace_code.rb
89
90
  - lib/eval_helper/if_code.rb
90
91
  - lib/eval_helper/if_code_after.rb
91
92
  - lib/eval_helper/require_code.rb
@@ -139,7 +140,9 @@ files:
139
140
  - lib/open_classes/object/my_methods.rb
140
141
  - lib/open_classes/object/to_bool.rb
141
142
  - lib/open_classes/string.rb
143
+ - lib/open_classes/string/comma_to_a.rb
142
144
  - lib/open_classes/string/heading_helper.rb
145
+ - lib/open_classes/string/hyphen_to_a.rb
143
146
  - lib/open_classes/string/justify_table.rb
144
147
  - lib/open_classes/string/say.rb
145
148
  - lib/open_classes/string/stripe.rb
@@ -158,6 +161,7 @@ files:
158
161
  - rubocop-todo.yml
159
162
  - spec/attributes_hashable_spec.rb
160
163
  - spec/attributes_initializable_spec.rb
164
+ - spec/eval_helper/each_brace_code_spec.rb
161
165
  - spec/eval_helper/if_code_after_spec.rb
162
166
  - spec/eval_helper/if_code_spec.rb
163
167
  - spec/eval_helper/require_code_spec.rb
@@ -206,6 +210,8 @@ files:
206
210
  - spec/open_classes/object/guard_spec.rb
207
211
  - spec/open_classes/object/my_methods_spec.rb
208
212
  - spec/open_classes/object/to_bool_spec.rb
213
+ - spec/open_classes/string/comma_to_a_spec.rb
214
+ - spec/open_classes/string/hyphen_to_a_spec.rb
209
215
  - spec/open_classes/string/justify_table_spec.rb
210
216
  - spec/open_classes/string/say_spec.rb
211
217
  - spec/open_classes/string/stripe_spec.rb
@@ -249,6 +255,7 @@ summary: Utilities
249
255
  test_files:
250
256
  - spec/attributes_hashable_spec.rb
251
257
  - spec/attributes_initializable_spec.rb
258
+ - spec/eval_helper/each_brace_code_spec.rb
252
259
  - spec/eval_helper/if_code_after_spec.rb
253
260
  - spec/eval_helper/if_code_spec.rb
254
261
  - spec/eval_helper/require_code_spec.rb
@@ -297,6 +304,8 @@ test_files:
297
304
  - spec/open_classes/object/guard_spec.rb
298
305
  - spec/open_classes/object/my_methods_spec.rb
299
306
  - spec/open_classes/object/to_bool_spec.rb
307
+ - spec/open_classes/string/comma_to_a_spec.rb
308
+ - spec/open_classes/string/hyphen_to_a_spec.rb
300
309
  - spec/open_classes/string/justify_table_spec.rb
301
310
  - spec/open_classes/string/say_spec.rb
302
311
  - spec/open_classes/string/stripe_spec.rb