tbpgr_utils 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/README.md +26 -0
- data/lib/open_classes/array.rb +17 -0
- data/lib/tbpgr_utils.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/array_spec.rb +52 -0
- data/spec/spec_helper.rb +0 -2
- data/tbpgr_utils.gemspec +0 -1
- metadata +11 -19
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -20,10 +20,22 @@ Or install it yourself as:
|
|
20
20
|
### List
|
21
21
|
| dsl| mean|
|
22
22
|
|:-----------|:------------|
|
23
|
+
|Array#together|loop all arrays by block|
|
23
24
|
|Object#boolean?|data type check for boolean|
|
24
25
|
|Object#my_methods|return public/protected/private self define methods|
|
25
26
|
|String#justify_table|justify pipe format table string|
|
26
27
|
|
28
|
+
### Array#together
|
29
|
+
~~~ruby
|
30
|
+
require 'tbpgr_utils'
|
31
|
+
|
32
|
+
alpha = %w{one two three}
|
33
|
+
numbers = %w{1 2 3}
|
34
|
+
[alpha, numbers].together do |first, second|
|
35
|
+
print "#{first}:#{second}\n" # => output one:1, two:2, three:3
|
36
|
+
end
|
37
|
+
~~~
|
38
|
+
|
27
39
|
### Object#boolean?
|
28
40
|
~~~ruby
|
29
41
|
require 'tbpgr_utils'
|
@@ -39,6 +51,19 @@ p "true".boolean? # =>false
|
|
39
51
|
~~~ruby
|
40
52
|
require 'tbpgr_utils'
|
41
53
|
|
54
|
+
class Hoge
|
55
|
+
def hgoe
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
def hige
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def hege
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
42
67
|
p Hoge.new.my_methods # =>[:hoge, :hige, :hege]
|
43
68
|
~~~
|
44
69
|
|
@@ -63,6 +88,7 @@ output
|
|
63
88
|
~~~
|
64
89
|
|
65
90
|
## History
|
91
|
+
* version 0.0.2 : loop all arrays by block.
|
66
92
|
* version 0.0.1 : first release.
|
67
93
|
|
68
94
|
## Contributing
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# =Array
|
4
|
+
class Array
|
5
|
+
# ==Arrays loop together
|
6
|
+
def together
|
7
|
+
self.each {|f|fail TypeError, "you have to use [Array1, Array2, ...] | #{f.class} is invalid" unless f.class == Array}
|
8
|
+
self.first.each_with_index do |i_v, i|
|
9
|
+
eval_each = []
|
10
|
+
self.each_with_index do |j_v, j|
|
11
|
+
eval_each << "self[#{j}][#{i}]"
|
12
|
+
end
|
13
|
+
eval_each_str = eval_each.join(",")
|
14
|
+
instance_eval "yield(#{eval_each_str})"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/tbpgr_utils.rb
CHANGED
data/lib/tbpgr_utils/version.rb
CHANGED
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
require "tbpgr_utils"
|
4
|
+
|
5
|
+
describe Array do
|
6
|
+
|
7
|
+
context :together do
|
8
|
+
cases = [
|
9
|
+
{
|
10
|
+
case_no: 1,
|
11
|
+
case_title: "valid case",
|
12
|
+
inputs: [[1, 2, 3], %w{one two three}],
|
13
|
+
expected: ["1:one", "2:two", "3:three"],
|
14
|
+
},
|
15
|
+
{
|
16
|
+
case_no: 2,
|
17
|
+
case_title: "contain nil case",
|
18
|
+
inputs: [[1, 2, 3], %w{one two}],
|
19
|
+
expected: ["1:one", "2:two", "3:"],
|
20
|
+
},
|
21
|
+
]
|
22
|
+
|
23
|
+
cases.each do |c|
|
24
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
25
|
+
begin
|
26
|
+
case_before c
|
27
|
+
|
28
|
+
# -- given --
|
29
|
+
# nothing
|
30
|
+
|
31
|
+
# -- when/then --
|
32
|
+
actual = []
|
33
|
+
c[:inputs].together do |first, second|
|
34
|
+
actual << "#{first}:#{second}"
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(actual).to eq(c[:expected])
|
38
|
+
ensure
|
39
|
+
case_after c
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def case_before(c)
|
44
|
+
# implement each case before
|
45
|
+
end
|
46
|
+
|
47
|
+
def case_after(c)
|
48
|
+
# implement each case after
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/tbpgr_utils.gemspec
CHANGED
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.
|
4
|
+
version: 0.0.2
|
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:
|
12
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
16
|
-
requirement: &
|
16
|
+
requirement: &22691088 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.3'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *22691088
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &22710612 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *22710612
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &22709268 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,18 +43,7 @@ dependencies:
|
|
43
43
|
version: 2.14.1
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: simplecov
|
49
|
-
requirement: &22257768 !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.8.2
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: *22257768
|
46
|
+
version_requirements: *22709268
|
58
47
|
description: Utilities
|
59
48
|
email:
|
60
49
|
- tbpgr@tbpgr.jp
|
@@ -68,10 +57,12 @@ files:
|
|
68
57
|
- LICENSE.txt
|
69
58
|
- README.md
|
70
59
|
- Rakefile
|
60
|
+
- lib/open_classes/array.rb
|
71
61
|
- lib/open_classes/object.rb
|
72
62
|
- lib/open_classes/string.rb
|
73
63
|
- lib/tbpgr_utils.rb
|
74
64
|
- lib/tbpgr_utils/version.rb
|
65
|
+
- spec/array_spec.rb
|
75
66
|
- spec/object_spec.rb
|
76
67
|
- spec/spec_helper.rb
|
77
68
|
- spec/string_spec.rb
|
@@ -102,6 +93,7 @@ signing_key:
|
|
102
93
|
specification_version: 3
|
103
94
|
summary: Utilities
|
104
95
|
test_files:
|
96
|
+
- spec/array_spec.rb
|
105
97
|
- spec/object_spec.rb
|
106
98
|
- spec/spec_helper.rb
|
107
99
|
- spec/string_spec.rb
|