tbpgr_utils 0.0.150 → 0.0.151
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +9 -9
- data/README.md +95 -32
- data/lib/attr_enumerable/attr_enumerable_helper.rb +52 -52
- data/lib/attr_enumerable/map_attr.rb +1 -1
- data/lib/eval_helper/attr_accessor_init_code.rb +3 -3
- data/lib/eval_helper/each_do_code.rb +26 -26
- data/lib/eval_helper/each_with_index_do_code.rb +26 -26
- data/lib/eval_helper/require_code.rb +1 -1
- data/lib/eval_helper/require_relative_code.rb +1 -1
- data/lib/eval_helper/set_variable_code.rb +1 -1
- data/lib/eval_helper/set_variables_code.rb +1 -1
- data/lib/eval_helper/times_code.rb +1 -1
- data/lib/ghostable.rb +1 -1
- data/lib/open_classes/array.rb +0 -2
- data/lib/open_classes/array/average.rb +17 -17
- data/lib/open_classes/array/gte_gte.rb +1 -1
- data/lib/open_classes/array/to_table.rb +1 -1
- data/lib/open_classes/array/together_clear.rb +24 -24
- data/lib/open_classes/array/together_compact.rb +44 -44
- data/lib/open_classes/array/together_empty.rb +1 -1
- data/lib/open_classes/array/together_include.rb +1 -1
- data/lib/open_classes/enumerable.rb +4 -0
- data/lib/open_classes/enumerable/if_else_map.rb +12 -0
- data/lib/open_classes/{array → enumerable}/kernel_send.rb +15 -15
- data/lib/open_classes/{array → enumerable}/sum.rb +3 -3
- data/lib/open_classes/hash/gte_gte.rb +45 -45
- data/lib/open_classes/integer/each_digit.rb +13 -13
- data/lib/open_classes/integer/each_digit_with_index.rb +13 -13
- data/lib/open_classes/integer/reverse_each_digit.rb +13 -13
- data/lib/open_classes/kernel/aa_ancestors.rb +1 -1
- data/lib/open_classes/numeric/is_ascii.rb +4 -4
- data/lib/open_classes/object/any_of.rb +1 -2
- data/lib/open_classes/object/to_bool.rb +1 -1
- data/lib/open_classes/string/ascii_unicode_html_table.rb +1 -1
- data/lib/open_classes/string/ascii_unicode_table.rb +1 -1
- data/lib/open_classes/string/is_meta_variable.rb +7 -7
- data/lib/open_classes/string/justify_table.rb +2 -2
- data/lib/open_classes/string/surround.rb +2 -2
- data/lib/open_classes/symbol/is_meta_variable.rb +6 -6
- data/lib/tbpgr_utils.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/lib/templatable.rb +1 -1
- data/rubocop-todo.yml +2 -36
- data/spec/attr_enumerable/each_attr_spec.rb +1 -1
- data/spec/attr_enumerable/each_attr_with_index_spec.rb +1 -1
- data/spec/attr_enumerable/first_attr_spec.rb +107 -107
- data/spec/attr_enumerable/include_attr_spec.rb +4 -4
- data/spec/attr_enumerable/last_attr_spec.rb +4 -4
- data/spec/attr_enumerable/map_attr_spec.rb +3 -3
- data/spec/attr_enumerable/reduce_attr_spec.rb +3 -3
- data/spec/attr_enumerable/reverse_attr_spec.rb +1 -1
- data/spec/attr_enumerable/sample_attr_spec.rb +3 -3
- data/spec/attr_enumerable/select_attr_spec.rb +2 -2
- data/spec/attr_enumerable/shuffle_attr_spec.rb +1 -1
- data/spec/attr_enumerable/slice_attr_spec.rb +1 -1
- data/spec/attributes_hashable_spec.rb +1 -1
- data/spec/attributes_initializable_spec.rb +21 -21
- data/spec/eval_helper/attr_accessor_init_code_spec.rb +1 -1
- data/spec/eval_helper/attr_init_class_code_spec.rb +1 -1
- data/spec/eval_helper/each_brace_code_spec.rb +2 -2
- data/spec/eval_helper/each_do_code_spec.rb +1 -1
- data/spec/eval_helper/each_with_index_brace_code_spec.rb +2 -2
- data/spec/eval_helper/each_with_index_do_code_spec.rb +2 -2
- data/spec/eval_helper/if_code_after_spec.rb +3 -3
- data/spec/eval_helper/if_code_spec.rb +3 -3
- data/spec/eval_helper/require_code_spec.rb +3 -3
- data/spec/eval_helper/require_relative_code_spec.rb +3 -3
- data/spec/eval_helper/set_variable_code_spec.rb +3 -3
- data/spec/{set_variables_code_spec.rb → eval_helper/set_variables_code_spec.rb} +15 -15
- data/spec/eval_helper/ternary_operator_spec.rb +5 -5
- data/spec/eval_helper/times_code_spec.rb +1 -1
- data/spec/eval_helper/unless_code_after_spec.rb +3 -3
- data/spec/eval_helper/unless_code_spec.rb +3 -3
- data/spec/familyable/familyable_spec.rb +6 -6
- data/spec/ghostable_spec.rb +5 -5
- data/spec/markdown/backquotes_spec.rb +4 -4
- data/spec/markdown/bold_spec.rb +4 -4
- data/spec/markdown/code_spec.rb +3 -3
- data/spec/markdown/codes_spec.rb +2 -2
- data/spec/markdown/heading_spec.rb +5 -5
- data/spec/markdown/hr_spec.rb +1 -1
- data/spec/markdown/italic_spec.rb +4 -4
- data/spec/markdown/link_spec.rb +1 -1
- data/spec/markdown/ol_spec.rb +3 -3
- data/spec/markdown/ul_spec.rb +3 -3
- data/spec/metasyntactic_variable_spec.rb +4 -4
- data/spec/open_classes/array/average_spec.rb +4 -4
- data/spec/open_classes/array/exchange_spec.rb +6 -6
- data/spec/open_classes/array/gte_gte_spec.rb +4 -4
- data/spec/open_classes/array/to_html_table_spec.rb +3 -3
- data/spec/open_classes/array/to_table_spec.rb +2 -2
- data/spec/open_classes/array/together_at_spec.rb +4 -4
- data/spec/open_classes/array/together_clear_spec.rb +3 -3
- data/spec/open_classes/array/together_compact_spec.rb +6 -6
- data/spec/open_classes/array/together_concat_spec.rb +3 -3
- data/spec/open_classes/array/together_delete_at_spec.rb +5 -5
- data/spec/open_classes/array/together_delete_if_spec.rb +4 -4
- data/spec/open_classes/array/together_delete_spec.rb +5 -5
- data/spec/open_classes/array/together_empty_spec.rb +4 -4
- data/spec/open_classes/array/together_fill_spec.rb +5 -5
- data/spec/open_classes/array/together_first_spec.rb +6 -6
- data/spec/open_classes/array/together_include_spec.rb +8 -8
- data/spec/open_classes/array/together_index_spec.rb +5 -5
- data/spec/open_classes/array/together_insert_spec.rb +5 -5
- data/spec/open_classes/array/together_last_spec.rb +6 -6
- data/spec/open_classes/array/together_map_spec.rb +14 -14
- data/spec/open_classes/array/together_pop_spec.rb +8 -8
- data/spec/open_classes/array/together_reduce_spec.rb +8 -8
- data/spec/open_classes/array/together_reverse_spec.rb +119 -119
- data/spec/open_classes/array/together_sample_spec.rb +8 -8
- data/spec/open_classes/array/together_select_spec.rb +6 -6
- data/spec/open_classes/array/together_shift_spec.rb +8 -8
- data/spec/open_classes/array/together_shuffle_spec.rb +3 -3
- data/spec/open_classes/array/together_slice_spec.rb +5 -5
- data/spec/open_classes/array/together_spec.rb +3 -3
- data/spec/open_classes/array/together_with_index_spec.rb +3 -3
- data/spec/open_classes/array/uniq_size_spec.rb +4 -4
- data/spec/open_classes/enumerable/if_else_map_spec.rb +45 -0
- data/spec/open_classes/{array → enumerable}/kernel_send_spec.rb +50 -43
- data/spec/open_classes/{array → enumerable}/sum_spec.rb +8 -2
- data/spec/open_classes/fixnum/to_fixnum_html_table_spec.rb +1 -1
- data/spec/open_classes/fixnum/to_fixnum_table_spec.rb +1 -1
- data/spec/open_classes/hash/gte_gte_spec.rb +4 -4
- data/spec/open_classes/hash/html_table_spec.rb +2 -2
- data/spec/open_classes/hash/table_spec.rb +2 -2
- data/spec/open_classes/integer/each_digit_spec.rb +2 -2
- data/spec/open_classes/integer/each_digit_with_index_spec.rb +2 -2
- data/spec/open_classes/integer/palindromic_prime_spec.rb +6 -6
- data/spec/open_classes/integer/reverse_each_digit_spec.rb +2 -2
- data/spec/open_classes/kernel/aa_ancestors_spec.rb +1 -1
- data/spec/open_classes/kernel/booleans_spec.rb +1 -1
- data/spec/open_classes/kernel/bulk_define_methods_spec.rb +5 -5
- data/spec/open_classes/kernel/bulk_puts_eval_spec.rb +1 -1
- data/spec/open_classes/kernel/evalb_spec.rb +2 -2
- data/spec/open_classes/kernel/exchange_spec.rb +2 -2
- data/spec/open_classes/kernel/hash_to_attributes_spec.rb +3 -3
- data/spec/open_classes/kernel/null_spec.rb +1 -1
- data/spec/open_classes/kernel/print_eval_spec.rb +3 -3
- data/spec/open_classes/kernel/puts_eval_spec.rb +3 -3
- data/spec/open_classes/module_spec.rb +3 -3
- data/spec/open_classes/numeric/dice_back_spec.rb +8 -8
- data/spec/open_classes/numeric/dozen_spec.rb +4 -4
- data/spec/open_classes/numeric/is_ascii_spec.rb +6 -6
- data/spec/open_classes/numeric/to_binary_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_binary_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_digit_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_digit_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_hex_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_hex_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_oct_html_table_spec.rb +1 -1
- data/spec/open_classes/numeric/to_oct_table_spec.rb +1 -1
- data/spec/open_classes/object/any_of_spec.rb +6 -6
- data/spec/open_classes/object/boolean_spec.rb +6 -6
- data/spec/open_classes/object/grep_instance_method_spec.rb +15 -15
- data/spec/open_classes/object/grep_method_spec.rb +6 -6
- data/spec/open_classes/object/guard_spec.rb +8 -8
- data/spec/open_classes/object/method_nameable_spec.rb +4 -4
- data/spec/open_classes/object/my_methods_spec.rb +2 -2
- data/spec/open_classes/object/null_spec.rb +1 -1
- data/spec/open_classes/object/to_bool_spec.rb +7 -7
- data/spec/open_classes/string/ascii1_other2_size_spec.rb +5 -5
- data/spec/open_classes/string/ascii_unicode_html_table_spec.rb +1 -1
- data/spec/open_classes/string/ascii_unicode_table_spec.rb +1 -1
- data/spec/open_classes/string/comma_to_a_spec.rb +1 -1
- data/spec/open_classes/string/cygwinpath_to_winpath_spec.rb +3 -3
- data/spec/open_classes/string/escape_double_quote_spec.rb +3 -3
- data/spec/open_classes/string/escape_quote_spec.rb +3 -3
- data/spec/open_classes/string/gte_gte_spec.rb +3 -3
- data/spec/open_classes/string/hyphen_to_a_spec.rb +1 -1
- data/spec/open_classes/string/is_meta_variable_spec.rb +3 -3
- data/spec/open_classes/string/justify_char_spec.rb +6 -6
- data/spec/open_classes/string/justify_table_spec.rb +6 -6
- data/spec/open_classes/string/say_spec.rb +2 -2
- data/spec/open_classes/string/spacing_spec.rb +6 -6
- data/spec/open_classes/string/surround_spec.rb +1 -1
- data/spec/open_classes/string/table_to_array_spec.rb +1 -1
- data/spec/open_classes/string/to_hatena_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_markdown_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_space2_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_space4_heading_spec.rb +5 -5
- data/spec/open_classes/string/to_tab_heading_spec.rb +5 -5
- data/spec/open_classes/string/unescape_double_quote_spec.rb +3 -3
- data/spec/open_classes/string/unescape_quote_spec.rb +3 -3
- data/spec/open_classes/string/uniq_size_spec.rb +4 -4
- data/spec/open_classes/string/uniq_spec.rb +4 -4
- data/spec/open_classes/string/winpath_to_cygwinpath_spec.rb +3 -3
- data/spec/open_classes/symbol/is_meta_variable_spec.rb +3 -3
- data/spec/simple_tournament_spec.rb +9 -9
- data/spec/templatable_spec.rb +2 -2
- data/spec/template_methodable_spec.rb +1 -1
- data/spec/test_toolbox/kernel_spec.rb +7 -7
- data/tbpgr_utils.gemspec +4 -4
- metadata +15 -11
@@ -1,13 +1,13 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
class Integer
|
4
|
-
# provide iterator for number's each digit with index
|
5
|
-
#
|
6
|
-
# === Example
|
7
|
-
#
|
8
|
-
# ret=[];12_345.each_digit_with_index { |v, i|ret << v + i };print ret # => [1, 3, 5, 7, 9]
|
9
|
-
#
|
10
|
-
def each_digit_with_index
|
11
|
-
abs.to_s.split('').map
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Integer
|
4
|
+
# provide iterator for number's each digit with index
|
5
|
+
#
|
6
|
+
# === Example
|
7
|
+
#
|
8
|
+
# ret=[];12_345.each_digit_with_index { |v, i|ret << v + i };print ret # => [1, 3, 5, 7, 9]
|
9
|
+
#
|
10
|
+
def each_digit_with_index
|
11
|
+
abs.to_s.split('').map(&:to_i).each_with_index { |v, i|yield(v, i) }
|
12
|
+
end
|
13
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
class Integer
|
4
|
-
# provide reverse iterator for number's each digit
|
5
|
-
#
|
6
|
-
# === Example
|
7
|
-
#
|
8
|
-
# ret=[];12345.reverse_each_digit { |v|ret << v+1 };print ret # => [6, 5, 4, 3, 2]
|
9
|
-
#
|
10
|
-
def reverse_each_digit
|
11
|
-
abs.to_s.split('').reverse.map
|
12
|
-
end
|
13
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Integer
|
4
|
+
# provide reverse iterator for number's each digit
|
5
|
+
#
|
6
|
+
# === Example
|
7
|
+
#
|
8
|
+
# ret=[];12345.reverse_each_digit { |v|ret << v+1 };print ret # => [6, 5, 4, 3, 2]
|
9
|
+
#
|
10
|
+
def reverse_each_digit
|
11
|
+
abs.to_s.split('').reverse.map(&:to_i).each { |v|yield(v) }
|
12
|
+
end
|
13
|
+
end
|
@@ -8,11 +8,11 @@ class Numeric
|
|
8
8
|
#
|
9
9
|
# 1,127,128 case
|
10
10
|
#
|
11
|
-
# 1.
|
12
|
-
# 127.
|
13
|
-
# 128.
|
11
|
+
# 1.ascii? # => return true
|
12
|
+
# 127.ascii? # => return true
|
13
|
+
# 128.ascii? # => return false
|
14
14
|
#
|
15
|
-
def
|
15
|
+
def ascii?
|
16
16
|
self < 128
|
17
17
|
end
|
18
18
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require'metasyntactic_variable'
|
2
|
+
require 'metasyntactic_variable'
|
3
3
|
|
4
4
|
# String
|
5
5
|
class String
|
@@ -7,13 +7,13 @@ class String
|
|
7
7
|
#
|
8
8
|
# ==== Examples
|
9
9
|
#
|
10
|
-
# 'foo'.
|
11
|
-
# 'bar'.
|
12
|
-
# 'baz'.
|
13
|
-
# ''.
|
14
|
-
# 'aaa'.
|
10
|
+
# 'foo'.meta_variable? # => true
|
11
|
+
# 'bar'.meta_variable? # => true
|
12
|
+
# 'baz'.meta_variable? # => true
|
13
|
+
# ''.meta_variable? # => false
|
14
|
+
# 'aaa'.meta_variable? # => false
|
15
15
|
#
|
16
|
-
def
|
16
|
+
def meta_variable?
|
17
17
|
MetasyntacticVariable.meta_variables.include? to_sym
|
18
18
|
end
|
19
19
|
end
|
@@ -20,14 +20,14 @@ class String
|
|
20
20
|
# |yusei |matsui |
|
21
21
|
def justify_table(position = :left)
|
22
22
|
return self if self.empty?
|
23
|
-
max_sizes =
|
23
|
+
max_sizes = column_maxes_table
|
24
24
|
return self if max_sizes.nil?
|
25
25
|
justify_lines_table max_sizes, position
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
-
def
|
30
|
+
def column_maxes_table
|
31
31
|
max_sizes = []
|
32
32
|
each_line do |line|
|
33
33
|
return nil unless table? line
|
@@ -47,7 +47,7 @@ class String
|
|
47
47
|
side = init_side(options)
|
48
48
|
inner_width = line_max
|
49
49
|
top_bottom = top_bottoms(top_bottom, inner_width)
|
50
|
-
ret = *each_line.reduce(["#{top_bottom}"]) { |
|
50
|
+
ret = *each_line.reduce(["#{top_bottom}"]) { |a, e|a << "#{side}#{e.chomp.ljust(inner_width)}#{side}" }
|
51
51
|
ret.push("#{top_bottom}").join("\n")
|
52
52
|
end
|
53
53
|
|
@@ -67,6 +67,6 @@ class String
|
|
67
67
|
|
68
68
|
def line_max
|
69
69
|
return 0 if self.empty?
|
70
|
-
each_line.max_by
|
70
|
+
each_line.max_by(&:size).chomp.size
|
71
71
|
end
|
72
72
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require'metasyntactic_variable'
|
2
|
+
require 'metasyntactic_variable'
|
3
3
|
|
4
4
|
# Symbol
|
5
5
|
class Symbol
|
@@ -7,12 +7,12 @@ class Symbol
|
|
7
7
|
#
|
8
8
|
# ==== Examples
|
9
9
|
#
|
10
|
-
# :foo.
|
11
|
-
# :bar.
|
12
|
-
# :baz.
|
13
|
-
# :aaa.
|
10
|
+
# :foo.meta_variable? # => true
|
11
|
+
# :bar.meta_variable? # => true
|
12
|
+
# :baz.meta_variable? # => true
|
13
|
+
# :aaa.meta_variable? # => false
|
14
14
|
#
|
15
|
-
def
|
15
|
+
def meta_variable?
|
16
16
|
MetasyntacticVariable.meta_variables.include? self
|
17
17
|
end
|
18
18
|
end
|
data/lib/tbpgr_utils.rb
CHANGED
data/lib/tbpgr_utils/version.rb
CHANGED
data/lib/templatable.rb
CHANGED
data/rubocop-todo.yml
CHANGED
@@ -5,44 +5,10 @@
|
|
5
5
|
# Note that changes in the inspected code, or installation of new
|
6
6
|
# versions of RuboCop, may require this file to be generated again.
|
7
7
|
|
8
|
-
# Offense count: 2
|
9
|
-
AccessorMethodName:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
# Offense count: 4
|
13
|
-
AmbiguousRegexpLiteral:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
# Offense count: 1
|
17
|
-
DoubleNegation:
|
18
|
-
Enabled: false
|
19
|
-
|
20
|
-
# Offense count: 3
|
21
|
-
# Configuration parameters: NamePrefixBlacklist.
|
22
|
-
PredicateName:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
# Offense count: 2
|
26
|
-
RegexpLiteral:
|
27
|
-
MaxSlashes: 0
|
28
|
-
|
29
|
-
# Offense count: 2
|
30
|
-
SelfAssignment:
|
31
|
-
Enabled: false
|
32
|
-
|
33
|
-
# Offense count: 11
|
34
|
-
# Configuration parameters: Methods.
|
35
|
-
SingleLineBlockParams:
|
36
|
-
Enabled: false
|
37
|
-
|
38
|
-
# Offense count: 2
|
39
|
-
SpaceBeforeFirstArg:
|
40
|
-
Enabled: false
|
41
|
-
|
42
8
|
# Offense count: 447
|
43
9
|
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
44
|
-
TrailingComma:
|
45
|
-
|
10
|
+
# TrailingComma:
|
11
|
+
# Enabled: false
|
46
12
|
|
47
13
|
# Offense count: 33
|
48
14
|
UnusedBlockArgument:
|
@@ -1,107 +1,107 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'attr_enumerable'
|
4
|
-
|
5
|
-
describe AttrEnumerable do
|
6
|
-
context :first_attr do
|
7
|
-
class AttrEnumerablePerson
|
8
|
-
attr_reader :name, :age
|
9
|
-
def initialize(name, age)
|
10
|
-
@name, @age = name, age
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class AttrEnumerablePersons
|
15
|
-
attr_reader :attr_enumerable_persons
|
16
|
-
include AttrEnumerable
|
17
|
-
def initialize(attr_enumerable_persons = [])
|
18
|
-
@attr_enumerable_persons = attr_enumerable_persons
|
19
|
-
end
|
20
|
-
|
21
|
-
def <<(person)
|
22
|
-
@attr_enumerable_persons << attr_enumerable_persons
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
cases = [
|
27
|
-
{
|
28
|
-
case_no: 1,
|
29
|
-
case_title: 'name case',
|
30
|
-
klass: AttrEnumerablePersons.new(
|
31
|
-
[
|
32
|
-
AttrEnumerablePerson.new('tanaka', 84),
|
33
|
-
AttrEnumerablePerson.new('tanaka', 20),
|
34
|
-
AttrEnumerablePerson.new('suzuki', 20)
|
35
|
-
]
|
36
|
-
),
|
37
|
-
method: :first_name,
|
38
|
-
first: nil,
|
39
|
-
expected: ['tanaka']
|
40
|
-
},
|
41
|
-
{
|
42
|
-
case_no: 2,
|
43
|
-
case_title: 'age case',
|
44
|
-
klass: AttrEnumerablePersons.new(
|
45
|
-
[
|
46
|
-
AttrEnumerablePerson.new('tanaka', 84),
|
47
|
-
AttrEnumerablePerson.new('tanaka', 20),
|
48
|
-
AttrEnumerablePerson.new('suzuki', 20)
|
49
|
-
]
|
50
|
-
),
|
51
|
-
method: :first_age,
|
52
|
-
first: 2,
|
53
|
-
expected: [84, 20]
|
54
|
-
},
|
55
|
-
{
|
56
|
-
case_no: 3,
|
57
|
-
case_title: 'over index case',
|
58
|
-
klass: AttrEnumerablePersons.new(
|
59
|
-
[
|
60
|
-
AttrEnumerablePerson.new('tanaka', 84),
|
61
|
-
AttrEnumerablePerson.new('tanaka', 20),
|
62
|
-
AttrEnumerablePerson.new('suzuki', 20)
|
63
|
-
]
|
64
|
-
),
|
65
|
-
method: :first_age,
|
66
|
-
first: 4,
|
67
|
-
expected: [84, 20, 20]
|
68
|
-
},
|
69
|
-
{
|
70
|
-
case_no: 4,
|
71
|
-
case_title: 'empty case',
|
72
|
-
klass: AttrEnumerablePersons.new([]),
|
73
|
-
method: :first_name,
|
74
|
-
first: nil,
|
75
|
-
expected: []
|
76
|
-
}
|
77
|
-
]
|
78
|
-
|
79
|
-
cases.each do |c|
|
80
|
-
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
81
|
-
begin
|
82
|
-
case_before c
|
83
|
-
|
84
|
-
# -- given --
|
85
|
-
# nothing
|
86
|
-
ary = c[:klass]
|
87
|
-
|
88
|
-
# -- when --
|
89
|
-
actual = c[:first] ? ary.send(c[:method], c[:first]) : ary.send(c[:method])
|
90
|
-
|
91
|
-
# -- then --
|
92
|
-
expect(Array(actual)).to match_array(c[:expected])
|
93
|
-
ensure
|
94
|
-
case_after c
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def case_before(c)
|
99
|
-
# implement each case before
|
100
|
-
end
|
101
|
-
|
102
|
-
def case_after(c)
|
103
|
-
# implement each case after
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'attr_enumerable'
|
4
|
+
|
5
|
+
describe AttrEnumerable do
|
6
|
+
context :first_attr do
|
7
|
+
class AttrEnumerablePerson
|
8
|
+
attr_reader :name, :age
|
9
|
+
def initialize(name, age)
|
10
|
+
@name, @age = name, age
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class AttrEnumerablePersons
|
15
|
+
attr_reader :attr_enumerable_persons
|
16
|
+
include AttrEnumerable
|
17
|
+
def initialize(attr_enumerable_persons = [])
|
18
|
+
@attr_enumerable_persons = attr_enumerable_persons
|
19
|
+
end
|
20
|
+
|
21
|
+
def <<(person)
|
22
|
+
@attr_enumerable_persons << attr_enumerable_persons
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
cases = [
|
27
|
+
{
|
28
|
+
case_no: 1,
|
29
|
+
case_title: 'name case',
|
30
|
+
klass: AttrEnumerablePersons.new(
|
31
|
+
[
|
32
|
+
AttrEnumerablePerson.new('tanaka', 84),
|
33
|
+
AttrEnumerablePerson.new('tanaka', 20),
|
34
|
+
AttrEnumerablePerson.new('suzuki', 20)
|
35
|
+
]
|
36
|
+
),
|
37
|
+
method: :first_name,
|
38
|
+
first: nil,
|
39
|
+
expected: ['tanaka']
|
40
|
+
},
|
41
|
+
{
|
42
|
+
case_no: 2,
|
43
|
+
case_title: 'age case',
|
44
|
+
klass: AttrEnumerablePersons.new(
|
45
|
+
[
|
46
|
+
AttrEnumerablePerson.new('tanaka', 84),
|
47
|
+
AttrEnumerablePerson.new('tanaka', 20),
|
48
|
+
AttrEnumerablePerson.new('suzuki', 20)
|
49
|
+
]
|
50
|
+
),
|
51
|
+
method: :first_age,
|
52
|
+
first: 2,
|
53
|
+
expected: [84, 20]
|
54
|
+
},
|
55
|
+
{
|
56
|
+
case_no: 3,
|
57
|
+
case_title: 'over index case',
|
58
|
+
klass: AttrEnumerablePersons.new(
|
59
|
+
[
|
60
|
+
AttrEnumerablePerson.new('tanaka', 84),
|
61
|
+
AttrEnumerablePerson.new('tanaka', 20),
|
62
|
+
AttrEnumerablePerson.new('suzuki', 20)
|
63
|
+
]
|
64
|
+
),
|
65
|
+
method: :first_age,
|
66
|
+
first: 4,
|
67
|
+
expected: [84, 20, 20]
|
68
|
+
},
|
69
|
+
{
|
70
|
+
case_no: 4,
|
71
|
+
case_title: 'empty case',
|
72
|
+
klass: AttrEnumerablePersons.new([]),
|
73
|
+
method: :first_name,
|
74
|
+
first: nil,
|
75
|
+
expected: []
|
76
|
+
}
|
77
|
+
]
|
78
|
+
|
79
|
+
cases.each do |c|
|
80
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
81
|
+
begin
|
82
|
+
case_before c
|
83
|
+
|
84
|
+
# -- given --
|
85
|
+
# nothing
|
86
|
+
ary = c[:klass]
|
87
|
+
|
88
|
+
# -- when --
|
89
|
+
actual = c[:first] ? ary.send(c[:method], c[:first]) : ary.send(c[:method])
|
90
|
+
|
91
|
+
# -- then --
|
92
|
+
expect(Array(actual)).to match_array(c[:expected])
|
93
|
+
ensure
|
94
|
+
case_after c
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def case_before(c)
|
99
|
+
# implement each case before
|
100
|
+
end
|
101
|
+
|
102
|
+
def case_after(c)
|
103
|
+
# implement each case after
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|