tbpgr_utils 0.0.139 → 0.0.140

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2eb75c4b5853cf7c53add6ef52f538786b6d6dea
4
- data.tar.gz: 6975b29af92ace33c6a5535c140bb8dd27d325e4
3
+ metadata.gz: 765fd5d72948e2ebe183d540b42c51911053357a
4
+ data.tar.gz: 74e3bfc5178ef209e400eb946577ee77816bf616
5
5
  SHA512:
6
- metadata.gz: 5f1fa6a0334cf5c0d84ba404ad3de34601aabbd51ac37465a9c874f070a56b8cfa4b9021e108541f87a6dc4d1a7fae4d1c90452cebe5ee6ce41ee5a875ed00e2
7
- data.tar.gz: 9378cbebade247ad277beddf19b487c2b01750ea4141e0e8d6fb3bfb85a48a430e2846306124ca7d391f65d36e0e328c35118c99c4ab06e77a5ddd2bee147883
6
+ metadata.gz: 29c057f97725d17414dc89f8400e8962725bc056a3ff97b4c28bcbc659a3a1e544068e12109bad81b35ad3dd8b9d928e2553ff24fc7be838de40c4e2900288c7
7
+ data.tar.gz: 76d706c10d9e887373c3561214065681f99163a14ec8f8ed72fa7854edcd03060b525ff9a3dcba07ce0e6fdba5daea49456034703e0793c2af784cb621da549e
data/README.md CHANGED
@@ -62,6 +62,7 @@ Or install it yourself as:
62
62
  |[TbpgrUtils Array#uniq_size](#arrayuniq_size) |return uniq size |
63
63
  |[AttrEnumerable.at_attr](#attrenumerableat_attr) |define at_xxx. it returns Class attributes(collection)'s at result. |
64
64
  |[AttrEnumerable.compact_attr](#attrenumerablecompact_attr) |define compact_xxx. it returns Class attributes(collection)'s that exclude nil elements. |
65
+ |[AttrEnumerable.concat_attr](#attrenumerableconcat_attr) |define concat_xxx. it returns Class attributes(collection) and argument array |
65
66
  |[AttrEnumerable.each_attr](#attrenumerableeach_attr) |define each_xxx. it call Class attributes(collection)'s attribute iterator |
66
67
  |[AttrEnumerable.each_attr_with_index](#attrenumerableeach_attr_with_index) |define each_xxx_with_index. it call Class attributes(collection)'s attribute iterator with index |
67
68
  |[AttrEnumerable.reverse_attr](#attrenumerablereverse_attr) |define reverse_xxx. it returns Class attributes(collection)'s reverse Array |
@@ -1172,6 +1173,38 @@ persons.compact_name 0 # => []
1172
1173
 
1173
1174
  [back to list](#list)
1174
1175
 
1176
+ ### AttrEnumerable.concat_attr
1177
+ ~~~ruby
1178
+ require 'attr_enumerable'
1179
+ class Person
1180
+ attr_reader :name, :age
1181
+ def initialize(name, age)
1182
+ @name, @age = name, age
1183
+ end
1184
+ end
1185
+
1186
+ class Persons
1187
+ attr_reader :persons
1188
+ include AttrEnumerable
1189
+ def initialize(persons = [])
1190
+ @persons = persons
1191
+ end
1192
+
1193
+ def <<(person)
1194
+ @persons << person
1195
+ end
1196
+ end
1197
+
1198
+ persons = Persons.new([Person.new("tanaka", 84), Person.new(nil, 99), Person.new("suzuki", nil)])
1199
+ persons.concat_name(["sato", "matsumoto"]) # => ['tanaka', nil, 'suzuki', "sato", "matsumoto"]
1200
+ persons.concat_age([20, 1]) # => [84, 99, nil, 20, 1]
1201
+
1202
+ persons = Persons.new([])
1203
+ persons.concat_name(["sato", "matsumoto"]) # => ["sato", "matsumoto"]
1204
+ ~~~
1205
+
1206
+ [back to list](#list)
1207
+
1175
1208
  ### AttrEnumerable.each_attr
1176
1209
  ~~~ruby
1177
1210
  require 'attr_enumerable'
@@ -3973,6 +4006,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3973
4006
  https://github.com/tbpgr/tbpgr_utils_snippets
3974
4007
 
3975
4008
  ## History
4009
+ * version 0.0.140 : add AttrEnumerable.concat_attr
3976
4010
  * version 0.0.139 : add AttrEnumerable.compact_attr
3977
4011
  * version 0.0.138 : add AttrEnumerable.at_attr
3978
4012
  * version 0.0.137 : add AttrEnumerable.reverse_attr
@@ -8,7 +8,8 @@ module AttrEnumerable
8
8
  { regexp: /^each_(.*)$/, call_method: :each_attr },
9
9
  { regexp: /^reverse_(.*)$/, call_method: :reverse_attr },
10
10
  { regexp: /^at_(.*)$/, call_method: :at_attr },
11
- { regexp: /^compact_(.*)$/, call_method: :compact_attr }
11
+ { regexp: /^compact_(.*)$/, call_method: :compact_attr },
12
+ { regexp: /^concat_(.*)$/, call_method: :concat_attr }
12
13
  ]
13
14
 
14
15
  # call attr enumerable method.
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require 'attr_enumerable/attr_enumerable_helper'
3
+
4
+ # AttrEnumerable
5
+ module AttrEnumerable
6
+ private
7
+ def concat_attr(attribute, method_name, *args, &block)
8
+ add_array = Array(*args)
9
+ return add_array if collection.empty?
10
+ super(method_name, *args) unless include_attr?(collection.first, attribute)
11
+ collection.map(&attribute.to_sym).concat(add_array)
12
+ end
13
+ end
@@ -4,6 +4,7 @@
4
4
  module AttrEnumerable
5
5
  require 'attr_enumerable/at_attr'
6
6
  require 'attr_enumerable/compact_attr'
7
+ require 'attr_enumerable/concat_attr'
7
8
  require 'attr_enumerable/each_attr'
8
9
  require 'attr_enumerable/each_attr_with_index'
9
10
  require 'attr_enumerable/reverse_attr'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.139'
5
+ VERSION = '0.0.140'
6
6
  end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'attr_enumerable'
4
+
5
+ describe AttrEnumerable do
6
+ context :concat_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(nil, 99),
34
+ AttrEnumerablePerson.new('suzuki', nil)
35
+ ]
36
+ ),
37
+ method: :concat_name,
38
+ add_array: ['sato', 'matsumoto'],
39
+ expected: ['tanaka', nil, 'suzuki', 'sato', 'matsumoto']
40
+ },
41
+ {
42
+ case_no: 2,
43
+ case_title: 'age case',
44
+ klass: AttrEnumerablePersons.new(
45
+ [
46
+ AttrEnumerablePerson.new('tanaka', 84),
47
+ AttrEnumerablePerson.new(nil, 99),
48
+ AttrEnumerablePerson.new('suzuki', nil)
49
+ ]
50
+ ),
51
+ method: :concat_age,
52
+ add_array: [20, 1],
53
+ expected: [84, 99, nil, 20, 1]
54
+ },
55
+ {
56
+ case_no: 3,
57
+ case_title: 'empty case',
58
+ klass: AttrEnumerablePersons.new([]),
59
+ method: :concat_name,
60
+ add_array: ['sato', 'matsumoto'],
61
+ expected: ['sato', 'matsumoto']
62
+ }
63
+ ]
64
+
65
+ cases.each do |c|
66
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
67
+ begin
68
+ case_before c
69
+
70
+ # -- given --
71
+ # nothing
72
+
73
+ # -- when --
74
+ actual = c[:klass].send c[:method], c[:add_array]
75
+
76
+ # -- then --
77
+ expect(actual).to eq(c[:expected])
78
+ ensure
79
+ case_after c
80
+ end
81
+ end
82
+
83
+ def case_before(c)
84
+ # implement each case before
85
+ end
86
+
87
+ def case_after(c)
88
+ # implement each case after
89
+ end
90
+ end
91
+ end
92
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbpgr_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.139
4
+ version: 0.0.140
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbpgr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-27 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -100,6 +100,7 @@ files:
100
100
  - lib/attr_enumerable/at_attr.rb
101
101
  - lib/attr_enumerable/attr_enumerable_helper.rb
102
102
  - lib/attr_enumerable/compact_attr.rb
103
+ - lib/attr_enumerable/concat_attr.rb
103
104
  - lib/attr_enumerable/each_attr.rb
104
105
  - lib/attr_enumerable/each_attr_with_index.rb
105
106
  - lib/attr_enumerable/reverse_attr.rb
@@ -261,6 +262,7 @@ files:
261
262
  - rubocop-todo.yml
262
263
  - spec/attr_enumerable/at_attr_spec.rb
263
264
  - spec/attr_enumerable/compact_attr_spec.rb
265
+ - spec/attr_enumerable/concat_attr_spec.rb
264
266
  - spec/attr_enumerable/each_attr_spec.rb
265
267
  - spec/attr_enumerable/each_attr_with_index_spec.rb
266
268
  - spec/attr_enumerable/reverse_attr_spec.rb
@@ -429,6 +431,7 @@ summary: Utilities
429
431
  test_files:
430
432
  - spec/attr_enumerable/at_attr_spec.rb
431
433
  - spec/attr_enumerable/compact_attr_spec.rb
434
+ - spec/attr_enumerable/concat_attr_spec.rb
432
435
  - spec/attr_enumerable/each_attr_spec.rb
433
436
  - spec/attr_enumerable/each_attr_with_index_spec.rb
434
437
  - spec/attr_enumerable/reverse_attr_spec.rb