tbpgr_utils 0.0.94 → 0.0.95

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -80,6 +80,7 @@ Or install it yourself as:
80
80
  |[TbpgrUtils Fixnum to_fixnum_html_table](#fixnum-to_fixnum_html_table) |return value is fixnum html table |
81
81
  |[TbpgrUtils Fixnum to_fixnum_table](#fixnumto_fixnum_table) |return value is fixnum table |
82
82
  |[Ghostable module](#ghostable) |help to create ghost method(dynamic method define by ussing method_missing + pattern-method-name) |
83
+ |[TbpgrUtils Hash#html_table](#hashhtml_table) |get html table string from key + value |
83
84
  |[TbpgrUtils Hash#table](#hashtable) |get pipe format table string from key + value |
84
85
  |[TbpgrUtils Kernel booleans](#kerne-booleans) |True or False instance aliases. |
85
86
  |[TbpgrUtils Kernel#bulk_define_methods](#kernelbulk_define_methods) |define methods to classes. methods have simple return value. |
@@ -1417,6 +1418,37 @@ dp_line __LINE__, filename: __FILE__, char: '@'
1417
1418
 
1418
1419
  [back to list](#list)
1419
1420
 
1421
+ ### Hash#html_table
1422
+ ~~~ruby
1423
+ require 'tbpgr_utils'
1424
+ {
1425
+ :key_1 => :value1,
1426
+ :key__2 => :value2,
1427
+ :key___3 => :value3,
1428
+ }.html_table
1429
+ ~~~
1430
+
1431
+ result
1432
+
1433
+ ~~~
1434
+ <table>
1435
+ <tr>
1436
+ <td>key_1</td>
1437
+ <td>value1</td>
1438
+ </tr>
1439
+ <tr>
1440
+ <td>key__2</td>
1441
+ <td>value2</td>
1442
+ </tr>
1443
+ <tr>
1444
+ <td>key___3</td>
1445
+ <td>value3</td>
1446
+ </tr>
1447
+ </table>
1448
+ ~~~
1449
+
1450
+ [back to list](#list)
1451
+
1420
1452
  ### Hash#table
1421
1453
  ~~~ruby
1422
1454
  require 'tbpgr_utils'
@@ -3073,6 +3105,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3073
3105
  https://github.com/tbpgr/tbpgr_utils_snippets
3074
3106
 
3075
3107
  ## History
3108
+ * version 0.0.95 : add Hash#html_table
3076
3109
  * version 0.0.94 : add String#unescape_quote
3077
3110
  * version 0.0.93 : add String#unescape_double_quote
3078
3111
  * version 0.0.92 : add Fixnum.to_fixnum_html_table
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ # Hash
4
+ class Hash
5
+ # get html table string from key + value
6
+ #
7
+ # ==== Examples
8
+ #
9
+ # valid commma case
10
+ #
11
+ # {
12
+ # :key_1 => :value1,
13
+ # :key__2 => :value2,
14
+ # :key___3 => :value3,
15
+ # }.html_table
16
+ #
17
+ # result
18
+ #
19
+ # <table>
20
+ # <tr>
21
+ # <td>key_1</td>
22
+ # <td>value1</td>
23
+ # </tr>
24
+ # <tr>
25
+ # <td>key__2</td>
26
+ # <td>value2</td>
27
+ # </tr>
28
+ # <tr>
29
+ # <td>key___3</td>
30
+ # <td>value3</td>
31
+ # </tr>
32
+ # </table>
33
+ #
34
+ def html_table
35
+ ret = [keys, values].treduce(["<table>"]) do |ret, one, other|
36
+ ret << " <tr>\n <td>#{one}</td>\n <td>#{other}</td>\n </tr>"
37
+ ret
38
+ end
39
+ ret.join("\n") + "\n</table>\n"
40
+ end
41
+ end
@@ -1,2 +1,3 @@
1
1
  # encoding: utf-8
2
2
  require 'open_classes/hash/table'
3
+ require 'open_classes/hash/html_table'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.94'
5
+ VERSION = '0.0.95'
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 :html_table do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: 'valid case',
11
+ input: {
12
+ key_1: :value1,
13
+ key__2: :value2,
14
+ key___3: :value3,
15
+ },
16
+ expected: <<-EOS
17
+ <table>
18
+ <tr>
19
+ <td>key_1</td>
20
+ <td>value1</td>
21
+ </tr>
22
+ <tr>
23
+ <td>key__2</td>
24
+ <td>value2</td>
25
+ </tr>
26
+ <tr>
27
+ <td>key___3</td>
28
+ <td>value3</td>
29
+ </tr>
30
+ </table>
31
+ EOS
32
+ },
33
+ ]
34
+
35
+ cases.each do |c|
36
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
37
+ begin
38
+ case_before c
39
+
40
+ # -- given --
41
+ # nothing
42
+
43
+ # -- when --
44
+ actual = c[:input].html_table
45
+
46
+ # -- then --
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,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.94
4
+ version: 0.0.95
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-04-11 00:00:00.000000000 Z
12
+ date: 2014-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &28496988 !ruby/object:Gem::Requirement
16
+ requirement: &28437660 !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: *28496988
24
+ version_requirements: *28437660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &28496700 !ruby/object:Gem::Requirement
27
+ requirement: &28437372 !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: *28496700
35
+ version_requirements: *28437372
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &28496472 !ruby/object:Gem::Requirement
38
+ requirement: &28437144 !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: *28496472
46
+ version_requirements: *28437144
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &28496148 !ruby/object:Gem::Requirement
49
+ requirement: &28436820 !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: *28496148
57
+ version_requirements: *28436820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &28495848 !ruby/object:Gem::Requirement
60
+ requirement: &28436520 !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: *28495848
68
+ version_requirements: *28436520
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -143,6 +143,7 @@ files:
143
143
  - lib/open_classes/fixnum/to_fixnum_html_table.rb
144
144
  - lib/open_classes/fixnum/to_fixnum_table.rb
145
145
  - lib/open_classes/hash.rb
146
+ - lib/open_classes/hash/html_table.rb
146
147
  - lib/open_classes/hash/table.rb
147
148
  - lib/open_classes/kernel.rb
148
149
  - lib/open_classes/kernel/aa_ancestors.rb
@@ -251,6 +252,7 @@ files:
251
252
  - spec/open_classes/file_spec.rb
252
253
  - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
253
254
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
255
+ - spec/open_classes/hash/html_table_spec.rb
254
256
  - spec/open_classes/hash/table_spec.rb
255
257
  - spec/open_classes/kernel/aa_ancestors_spec.rb
256
258
  - spec/open_classes/kernel/booleans_spec.rb
@@ -380,6 +382,7 @@ test_files:
380
382
  - spec/open_classes/file_spec.rb
381
383
  - spec/open_classes/fixnum/to_fixnum_html_table_spec.rb
382
384
  - spec/open_classes/fixnum/to_fixnum_table_spec.rb
385
+ - spec/open_classes/hash/html_table_spec.rb
383
386
  - spec/open_classes/hash/table_spec.rb
384
387
  - spec/open_classes/kernel/aa_ancestors_spec.rb
385
388
  - spec/open_classes/kernel/booleans_spec.rb