tbpgr_utils 0.0.124 → 0.0.125

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abc47f0e31b15cdf12a627961e0f4c286731db50
4
- data.tar.gz: c96f77f49a40f07e6aabf03644ac57235bcbd60a
3
+ metadata.gz: 5fc1598c4a9745836b69d3e693518e378ed50524
4
+ data.tar.gz: 33fbfd44ef3af84f4255d67af96f4698b5fe5b84
5
5
  SHA512:
6
- metadata.gz: 5e6275aa412ed95ff54536aa8510ccf3652206b2f731e077f66a364d4835e0a006502194122138c266b733a0e161f0bd9f1de7b4ca0bbc1adb5581c8bf2c54e9
7
- data.tar.gz: 5a516285c429da9a5d9e1a81f942cc9b496f3525724fe2c067aae9b765d7e490e4de728f1c9d1f921772b3f92f16400c117064bce92fafa01bf45d40273eb73e
6
+ metadata.gz: f36daa7c6afa67373d06f7d5b0205de4478762fe468731e80bc8d45c22bfcc6ca04aee8fb5243782f60239d4289a99f42c12d7d22110bc0b63fc6567d0cd1fa0
7
+ data.tar.gz: 273b432875e68ae54476dc0cf7550f2f28c2409d56296630eae0a6db32c041e209aa20de12b3810354c15e1b9b32e7752c2b7d5e34e12d9c2ab617f9893c41bf
data/README.md CHANGED
@@ -83,6 +83,7 @@ Or install it yourself as:
83
83
  |[TbpgrUtils Fixnum to_fixnum_html_table](#fixnum-to_fixnum_html_table) |return value is fixnum html table |
84
84
  |[TbpgrUtils Fixnum to_fixnum_table](#fixnumto_fixnum_table) |return value is fixnum table |
85
85
  |[Ghostable module](#ghostable) |help to create ghost method(dynamic method define by ussing method_missing + pattern-method-name) |
86
+ |[TbpgrUtils Hash#>>](#hash) |return HashContext for each execute |
86
87
  |[TbpgrUtils Hash#html_table](#hashhtml_table) |get html table string from key + value |
87
88
  |[TbpgrUtils Hash#table](#hashtable) |get pipe format table string from key + value |
88
89
  |[TbpgrUtils Integer#palindromic_prime?](#integerpalindromic_prime) |Returns true if value is palindromic prime, false for a composite. |
@@ -1457,6 +1458,16 @@ dp_line __LINE__, filename: __FILE__, char: '@'
1457
1458
 
1458
1459
  [back to list](#list)
1459
1460
 
1461
+ ### Hash#>>
1462
+ ~~~ruby
1463
+ require 'tbpgr_utils'
1464
+ h = {key1: "value1", key2: "value2"}
1465
+ h.>>.upcase # => {key1: "VALUE1", key2: "VALUE2"}
1466
+ h.>>.+('_hoge') # => {key1: "value1_hoge", key2: "value2_hoge"}
1467
+ ~~~
1468
+
1469
+ [back to list](#list)
1470
+
1460
1471
  ### Hash#html_table
1461
1472
  ~~~ruby
1462
1473
  require 'tbpgr_utils'
@@ -3603,6 +3614,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3603
3614
  https://github.com/tbpgr/tbpgr_utils_snippets
3604
3615
 
3605
3616
  ## History
3617
+ * version 0.0.125 : add Hash#>>
3606
3618
  * version 0.0.124 : change spec of Array#>>, String#>>
3607
3619
  * version 0.0.123 : add String#>>
3608
3620
  * version 0.0.122 : add String#justify_char
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+
3
+ # HashContext
4
+ class HashContext
5
+ attr_reader :receiver
6
+ def initialize(receiver)
7
+ @receiver = receiver
8
+ end
9
+
10
+ def method_missing(method_name, *args , &block)
11
+ result = nil
12
+ if args.size > 0
13
+ receiver.reduce({}) do |ret, (key, value)|
14
+ value = value.send method_name, *args
15
+ ret[key] = value
16
+ ret
17
+ end
18
+ else
19
+ receiver.reduce({}) do |ret, (key , value)|
20
+ value = value.send method_name
21
+ ret[key] = value
22
+ ret
23
+ end
24
+ end
25
+ end
26
+
27
+ def to_h
28
+ @receiver
29
+ end
30
+ end
31
+
32
+ # Hash
33
+ class Hash
34
+ # return HashContext for each execute
35
+ #
36
+ # === Example
37
+ #
38
+ # h = {key1: "value1", key2: "value2"}
39
+ # h.>>.upcase # => {key1: "VALUE1", key2: "VALUE2"}
40
+ # h.>>.+('_hoge') # => {key1: "value1_hoge", key2: "value2_hoge"}
41
+ #
42
+ def >>(dummy = nil)
43
+ HashContext.new(self)
44
+ end
45
+ end
@@ -1,3 +1,4 @@
1
1
  # encoding: utf-8
2
- require 'open_classes/hash/table'
2
+ require 'open_classes/hash/gte_gte'
3
3
  require 'open_classes/hash/html_table'
4
+ require 'open_classes/hash/table'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.124'
5
+ VERSION = '0.0.125'
6
6
  end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'tbpgr_utils'
4
+
5
+ describe Hash do
6
+ context :>> do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'no args case',
11
+ input: { key1: 'value1', key2: 'value2' },
12
+ method_name: :upcase,
13
+ expected: { key1: 'VALUE1', key2: 'VALUE2' },
14
+ },
15
+ {
16
+ case_no: 2,
17
+ case_title: 'have args case',
18
+ input: { key1: 'value1', key2: 'value2' },
19
+ method_name: :+,
20
+ args: '_hoge',
21
+ expected: { key1: 'value1_hoge', key2: 'value2_hoge' },
22
+ },
23
+ {
24
+ case_no: 3,
25
+ case_title: 'to_h case',
26
+ input: { key1: 'value1', key2: 'value2' },
27
+ method_name: :to_h,
28
+ expected: { key1: 'value1', key2: 'value2' },
29
+ },
30
+ ]
31
+
32
+ cases.each do |c|
33
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
34
+ begin
35
+ case_before c
36
+
37
+ # -- given --
38
+ # nothing
39
+
40
+ # -- when/then --
41
+ if c[:args]
42
+ actual = c[:input].>>.send c[:method_name], *c[:args]
43
+ else
44
+ actual = c[:input].>>.send c[:method_name]
45
+ end
46
+
47
+ expect(actual).to eq(c[:expected])
48
+ ensure
49
+ case_after c
50
+ end
51
+ end
52
+
53
+ def case_before(c)
54
+ # implement each case before
55
+ end
56
+
57
+ def case_after(c)
58
+ # implement each case after
59
+ end
60
+ end
61
+ end
62
+ 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.124
4
+ version: 0.0.125
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-11 00:00:00.000000000 Z
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -171,6 +171,7 @@ files:
171
171
  - lib/open_classes/fixnum/to_fixnum_html_table.rb
172
172
  - lib/open_classes/fixnum/to_fixnum_table.rb
173
173
  - lib/open_classes/hash.rb
174
+ - lib/open_classes/hash/gte_gte.rb
174
175
  - lib/open_classes/hash/html_table.rb
175
176
  - lib/open_classes/hash/table.rb
176
177
  - lib/open_classes/integer.rb
@@ -306,6 +307,7 @@ files:
306
307
  - spec/open_classes/array/together_with_index_spec.rb
307
308
  - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
308
309
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
310
+ - spec/open_classes/hash/gte_gte_spec.rb
309
311
  - spec/open_classes/hash/html_table_spec.rb
310
312
  - spec/open_classes/hash/table_spec.rb
311
313
  - spec/open_classes/integer/palindromic_prime_spec.rb
@@ -460,6 +462,7 @@ test_files:
460
462
  - spec/open_classes/array/together_with_index_spec.rb
461
463
  - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
462
464
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
465
+ - spec/open_classes/hash/gte_gte_spec.rb
463
466
  - spec/open_classes/hash/html_table_spec.rb
464
467
  - spec/open_classes/hash/table_spec.rb
465
468
  - spec/open_classes/integer/palindromic_prime_spec.rb