tbpgr_utils 0.0.65 → 0.0.66

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/README.md CHANGED
@@ -61,6 +61,7 @@ Or install it yourself as:
61
61
  |[EvalHelper#each_do_code](#evalhelpereach_do_code) |create each do code, for eval |
62
62
  |[EvalHelper#each_brace_code](#evalhelpereach_brace_code) |create each brace single line code, for eval |
63
63
  |[EvalHelper#each_with_index_brace_code](#evalhelpereach_with_index_brace_code) |create eachwith_index_ brace single line code, for eval |
64
+ |[EvalHelper#each_with_index_do_code](#evalhelpereach_with_index_do_code) |create eachwith_index_ do code, for eval |
64
65
  |[EvalHelper#if_code](#evalhelperif_code) |create if strings, for eval |
65
66
  |[EvalHelper#if_code_after](#evalhelperif_code_after) |create after-if strings, for eval |
66
67
  |[EvalHelper#require_code](#evalhelperrequire_code) |create require strings, for eval |
@@ -1437,7 +1438,27 @@ hash = {
1437
1438
  target: '[:a, :b]',
1438
1439
  proc: 'puts "#{i}:#{v}"',
1439
1440
  }
1440
- EvalHelperEachWithIndexBraceTest.new.hoge(hash) # => return '[:a, :b].each { |v, i|puts "#{i}:#{v}" }'
1441
+ EvalHelperEachWithIndexBraceTest.new.hoge(hash) # => return '[:a, :b].each_with_index { |v, i|puts "#{i}:#{v}" }'
1442
+ ~~~
1443
+
1444
+ [back to list](#list)
1445
+
1446
+ ### EvalHelper#each_with_index_do_code
1447
+ ~~~ruby
1448
+ require 'eval_helper'
1449
+ class EvalHelperEachWithIndexDoTest
1450
+ include EvalHelper
1451
+
1452
+ def hoge(hash)
1453
+ each_with_index_do_code(hash[:target], hash[:proc])
1454
+ end
1455
+ end
1456
+
1457
+ hash = {
1458
+ target: '[:a, :b]',
1459
+ proc: "puts \"\#{i}:\#{v}1\"\nputs \"\#{i}:\#{v}2\"\n",
1460
+ }
1461
+ EvalHelperEachWithIndexDoTest.new.hoge(hash) # => return "[:a, :b].each_with_index do |v, i|\n puts \"\#{i}:\#{v}1\"\n puts \"\#{i}:\#{v}2\"\nend"
1441
1462
  ~~~
1442
1463
 
1443
1464
  [back to list](#list)
@@ -2455,6 +2476,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
2455
2476
  https://github.com/tbpgr/tbpgr_utils_snippets
2456
2477
 
2457
2478
  ## History
2479
+ * version 0.0.66 : add EvalHelper#each_with_index_do_code
2458
2480
  * version 0.0.65 : add EvalHelper#each_with_index_brace_code
2459
2481
  * version 0.0.64 : add EvalHelper#each_do_code
2460
2482
  * version 0.0.63 : add EvalHelper#each_brace_code, String#hyphen_to_a, String#commma_to_a
@@ -20,6 +20,6 @@ module EvalHelper
20
20
  # EvalHelperEachWithIndexBraceTest.new.hoge(hash) # => return '[:a, :b].each { |v, i|puts "#{i}:#{v}" }'
21
21
  #
22
22
  def each_with_index_brace_code(target, proc)
23
- "#{target}.each { |v, i|#{proc} }"
23
+ "#{target}.each_with_index { |v, i|#{proc} }"
24
24
  end
25
25
  end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ module EvalHelper
4
+ # create each with index do single line code, for eval
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # class EvalHelperEachWithIndexDoTest
9
+ # include EvalHelper
10
+ #
11
+ # def hoge(hash)
12
+ # each_with_index_do_code(hash[:target], hash[:proc])
13
+ # end
14
+ # end
15
+ #
16
+ # hash = {
17
+ # target: '[:a, :b]',
18
+ # proc: "puts \"\#{i}:\#{v}1\"\nputs \"\#{i}:\#{v}2\"\n",
19
+ # }
20
+ # EvalHelperEachWithIndexDoTest.new.hoge(hash) # => return "[:a, :b].each_with_index do |v, i|\n puts \"\#{i}:\#{v}1\"\n puts \"\#{i}:\#{v}2\"\nend"
21
+ #
22
+ def each_with_index_do_code(target, proc)
23
+ "#{target}.each { |v, i|#{proc} }"
24
+ indented = proc.split("\n").reduce([]) { |ret, v|ret << " #{v}" ; ret }.join("\n")
25
+ "#{target}.each_with_index do |v, i|\n#{indented}\nend"
26
+ end
27
+ end
data/lib/eval_helper.rb CHANGED
@@ -4,6 +4,7 @@ module EvalHelper
4
4
  require 'eval_helper/each_brace_code'
5
5
  require 'eval_helper/each_do_code'
6
6
  require 'eval_helper/each_with_index_brace_code'
7
+ require 'eval_helper/each_with_index_do_code'
7
8
  require 'eval_helper/if_code'
8
9
  require 'eval_helper/if_code_after'
9
10
  require 'eval_helper/require_code'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.65'
5
+ VERSION = '0.0.66'
6
6
  end
@@ -14,7 +14,7 @@ describe 'EvalHelper' do
14
14
  cases = [
15
15
  {
16
16
  case_no: 1,
17
- case_title: 'unless case',
17
+ case_title: 'valid case',
18
18
  target: '[:a, :b]',
19
19
  proc: "puts \"\#{v}1\"\nputs \"\#{v}2\"\n",
20
20
  expected: "[:a, :b].each do |v|\n puts \"\#{v}1\"\n puts \"\#{v}2\"\nend",
@@ -17,7 +17,7 @@ describe 'EvalHelper' do
17
17
  case_title: 'unless case',
18
18
  target: '[:a, :b]',
19
19
  proc: 'puts "#{i}:#{v}"',
20
- expected: '[:a, :b].each { |v, i|puts "#{i}:#{v}" }',
20
+ expected: '[:a, :b].each_with_index { |v, i|puts "#{i}:#{v}" }',
21
21
  },
22
22
  ]
23
23
 
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'eval_helper'
4
+
5
+ describe 'EvalHelper' do
6
+ context :each_with_index_do_code do
7
+ class EvalHelperEachWithIndexDoTest
8
+ include EvalHelper
9
+
10
+ def hoge(hash)
11
+ each_with_index_do_code(hash[:target], hash[:proc])
12
+ end
13
+ end
14
+ cases = [
15
+ {
16
+ case_no: 1,
17
+ case_title: 'valid case',
18
+ target: '[:a, :b]',
19
+ proc: "puts \"\#{i}:\#{v}1\"\nputs \"\#{i}:\#{v}2\"\n",
20
+ expected: "[:a, :b].each_with_index do |v, i|\n puts \"\#{i}:\#{v}1\"\n puts \"\#{i}:\#{v}2\"\nend",
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 = EvalHelperEachWithIndexDoTest.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
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.65
4
+ version: 0.0.66
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-13 00:00:00.000000000 Z
12
+ date: 2014-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &25456200 !ruby/object:Gem::Requirement
16
+ requirement: &21744960 !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: *25456200
24
+ version_requirements: *21744960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &25455912 !ruby/object:Gem::Requirement
27
+ requirement: &21744672 !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: *25455912
35
+ version_requirements: *21744672
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &25455684 !ruby/object:Gem::Requirement
38
+ requirement: &21744444 !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: *25455684
46
+ version_requirements: *21744444
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &25455360 !ruby/object:Gem::Requirement
49
+ requirement: &21744120 !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: *25455360
57
+ version_requirements: *21744120
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &25455060 !ruby/object:Gem::Requirement
60
+ requirement: &21743820 !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: *25455060
68
+ version_requirements: *21743820
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -89,6 +89,7 @@ files:
89
89
  - lib/eval_helper/each_brace_code.rb
90
90
  - lib/eval_helper/each_do_code.rb
91
91
  - lib/eval_helper/each_with_index_brace_code.rb
92
+ - lib/eval_helper/each_with_index_do_code.rb
92
93
  - lib/eval_helper/if_code.rb
93
94
  - lib/eval_helper/if_code_after.rb
94
95
  - lib/eval_helper/require_code.rb
@@ -166,6 +167,7 @@ files:
166
167
  - spec/eval_helper/each_brace_code_spec.rb
167
168
  - spec/eval_helper/each_do_code_spec.rb
168
169
  - spec/eval_helper/each_with_index_brace_code_spec.rb
170
+ - spec/eval_helper/each_with_index_do_code_spec.rb
169
171
  - spec/eval_helper/if_code_after_spec.rb
170
172
  - spec/eval_helper/if_code_spec.rb
171
173
  - spec/eval_helper/require_code_spec.rb
@@ -262,6 +264,7 @@ test_files:
262
264
  - spec/eval_helper/each_brace_code_spec.rb
263
265
  - spec/eval_helper/each_do_code_spec.rb
264
266
  - spec/eval_helper/each_with_index_brace_code_spec.rb
267
+ - spec/eval_helper/each_with_index_do_code_spec.rb
265
268
  - spec/eval_helper/if_code_after_spec.rb
266
269
  - spec/eval_helper/if_code_spec.rb
267
270
  - spec/eval_helper/require_code_spec.rb