tbpgr_utils 0.0.95 → 0.0.96

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -98,6 +98,7 @@ Or install it yourself as:
98
98
  |[TbpgrUtils Numeric#dice_back](#numericdice_back) |return dice back number |
99
99
  |[TbpgrUtils Numeric#dozen](#numericdozen) |get dozen number |
100
100
  |[TbpgrUtils Numeric#is_ascii?](#numericis_ascii) |get is_ascii number |
101
+ |[TbpgrUtils Numeric to_binary_html_table](#numeric-to_binary_html_table) |binary html table |
101
102
  |[TbpgrUtils Numeric to_binary_table](#numeric-to_binary_table) |binary table |
102
103
  |[TbpgrUtils Numeric to_digit_table](#numeric-to_digit_table) |digit table |
103
104
  |[TbpgrUtils Numeric to_hex_table](#numeric-to_hex_table) |hex table |
@@ -2381,6 +2382,34 @@ require 'tbpgr_utils'
2381
2382
 
2382
2383
  [back to list](#list)
2383
2384
 
2385
+ ### Numeric to_binary_html_table
2386
+
2387
+ [back to list](#list)
2388
+ ~~~ruby
2389
+ require 'tbpgr_utils'
2390
+ Numeric.to_binary_html_table(255, 256)
2391
+ ~~~
2392
+
2393
+ result
2394
+ ~~~
2395
+ <table>
2396
+ <tr>
2397
+ <th>10digit</th>
2398
+ <th>2digit</th>
2399
+ </tr>
2400
+ <tr>
2401
+ <td>255</td>
2402
+ <td>0000000011111111</td>
2403
+ </tr>
2404
+ <tr>
2405
+ <td>256</td>
2406
+ <td>0000000100000000</td>
2407
+ </tr>
2408
+ </table>
2409
+ ~~~
2410
+
2411
+ [back to list](#list)
2412
+
2384
2413
  ### Numeric to_binary_table
2385
2414
  1 to 3 case
2386
2415
  ~~~ruby
@@ -3105,6 +3134,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
3105
3134
  https://github.com/tbpgr/tbpgr_utils_snippets
3106
3135
 
3107
3136
  ## History
3137
+ * version 0.0.96 : add Numeric.to_binary_html_table
3108
3138
  * version 0.0.95 : add Hash#html_table
3109
3139
  * version 0.0.94 : add String#unescape_quote
3110
3140
  * version 0.0.93 : add String#unescape_double_quote
@@ -1,41 +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
+ # 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
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ # Numeric
4
+ class Numeric
5
+ # binary table
6
+ #
7
+ # ==== Examples
8
+ #
9
+ # 1 to 3 case
10
+ #
11
+ # Numeric.to_binary_html_table(1, 3)
12
+ #
13
+ # result
14
+ #
15
+ # <table>
16
+ # <tr>
17
+ # <th>10digit</th>
18
+ # <th>2digit</th>
19
+ # </tr>
20
+ # <tr>
21
+ # <td>255</td>
22
+ # <td>0000000011111111</td>
23
+ # </tr>
24
+ # <tr>
25
+ # <td>256</td>
26
+ # <td>0000000100000000</td>
27
+ # </tr>
28
+ # </table>
29
+ #
30
+ def self.to_binary_html_table(from = 1, to = 10)
31
+ ret = []
32
+ size = to.to_s(2).size - 1
33
+ pad = (size / 8 + 1) * 8
34
+ ret << "<table>\n <tr>\n <th>10digit</th>\n <th>2digit</th>\n </tr>"
35
+
36
+ (from..to).each { |i|ret << " <tr>\n <td>#{i}</td>\n <td>#{i.to_s(2).rjust(pad, '0')}</td>\n </tr>" }
37
+ ret.join("\n") + "\n</table>\n"
38
+ end
39
+ end
@@ -3,6 +3,7 @@ require 'open_classes/numeric/dice_back'
3
3
  require 'open_classes/numeric/dozen'
4
4
  require 'open_classes/numeric/is_ascii'
5
5
  require 'open_classes/numeric/to_binary_table'
6
+ require 'open_classes/numeric/to_binary_html_table'
6
7
  require 'open_classes/numeric/to_digit_table'
7
8
  require 'open_classes/numeric/to_hex_table'
8
9
  require 'open_classes/numeric/to_oct_table'
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.95'
5
+ VERSION = '0.0.96'
6
6
  end
@@ -11,7 +11,7 @@ describe Familyable::Family do
11
11
  persons: [
12
12
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
13
13
  b = Familyable::Person.new(id: 2, parent_ids: []),
14
- c = Familyable::Person.new(id: 3, parent_ids: [4],),
14
+ c = Familyable::Person.new(id: 3, parent_ids: [4], ),
15
15
  d = Familyable::Person.new(id: 4, parent_ids: []),
16
16
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
17
17
  ],
@@ -59,7 +59,7 @@ describe Familyable::Family do
59
59
  persons: [
60
60
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
61
61
  b = Familyable::Person.new(id: 2, parent_ids: []),
62
- c = Familyable::Person.new(id: 3, parent_ids: [4],),
62
+ c = Familyable::Person.new(id: 3, parent_ids: [4], ),
63
63
  d = Familyable::Person.new(id: 4, parent_ids: []),
64
64
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
65
65
  ],
@@ -107,7 +107,7 @@ describe Familyable::Family do
107
107
  persons: [
108
108
  a = Familyable::Person.new(id: 1, parent_ids: [2, 3]),
109
109
  b = Familyable::Person.new(id: 2, parent_ids: []),
110
- c = Familyable::Person.new(id: 3, parent_ids: [4],),
110
+ c = Familyable::Person.new(id: 3, parent_ids: [4], ),
111
111
  d = Familyable::Person.new(id: 4, parent_ids: [3]),
112
112
  e = Familyable::Person.new(id: 5, parent_ids: [2]),
113
113
  ],
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'tbpgr_utils'
4
+
5
+ describe Numeric do
6
+ context :to_binary_html_table do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: '1-3 case',
11
+ from: 1,
12
+ to: 3,
13
+ expected: <<-EOS
14
+ <table>
15
+ <tr>
16
+ <th>10digit</th>
17
+ <th>2digit</th>
18
+ </tr>
19
+ <tr>
20
+ <td>1</td>
21
+ <td>00000001</td>
22
+ </tr>
23
+ <tr>
24
+ <td>2</td>
25
+ <td>00000010</td>
26
+ </tr>
27
+ <tr>
28
+ <td>3</td>
29
+ <td>00000011</td>
30
+ </tr>
31
+ </table>
32
+ EOS
33
+ },
34
+ {
35
+ case_no: 2,
36
+ case_title: '255-256 case',
37
+ from: 255,
38
+ to: 256,
39
+ expected: <<-EOS
40
+ <table>
41
+ <tr>
42
+ <th>10digit</th>
43
+ <th>2digit</th>
44
+ </tr>
45
+ <tr>
46
+ <td>255</td>
47
+ <td>0000000011111111</td>
48
+ </tr>
49
+ <tr>
50
+ <td>256</td>
51
+ <td>0000000100000000</td>
52
+ </tr>
53
+ </table>
54
+ EOS
55
+ },
56
+ ]
57
+
58
+ cases.each do |c|
59
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
60
+ begin
61
+ case_before c
62
+
63
+ # -- given --
64
+ # nothing
65
+
66
+ # -- when --
67
+ actual = Numeric.to_binary_html_table(c[:from], c[:to])
68
+
69
+ # -- then --
70
+ expect(actual).to eq(c[:expected])
71
+ ensure
72
+ case_after c
73
+ end
74
+ end
75
+
76
+ def case_before(c)
77
+ # implement each case before
78
+ end
79
+
80
+ def case_after(c)
81
+ # implement each case after
82
+ end
83
+ end
84
+ end
85
+ 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.95
4
+ version: 0.0.96
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-12 00:00:00.000000000 Z
12
+ date: 2014-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &28437660 !ruby/object:Gem::Requirement
16
+ requirement: &28445448 !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: *28437660
24
+ version_requirements: *28445448
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &28437372 !ruby/object:Gem::Requirement
27
+ requirement: &28445160 !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: *28437372
35
+ version_requirements: *28445160
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &28437144 !ruby/object:Gem::Requirement
38
+ requirement: &28444932 !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: *28437144
46
+ version_requirements: *28444932
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &28436820 !ruby/object:Gem::Requirement
49
+ requirement: &28444608 !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: *28436820
57
+ version_requirements: *28444608
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &28436520 !ruby/object:Gem::Requirement
60
+ requirement: &28444308 !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: *28436520
68
+ version_requirements: *28444308
69
69
  description: Utilities
70
70
  email:
71
71
  - tbpgr@tbpgr.jp
@@ -158,6 +158,7 @@ files:
158
158
  - lib/open_classes/numeric/dice_back.rb
159
159
  - lib/open_classes/numeric/dozen.rb
160
160
  - lib/open_classes/numeric/is_ascii.rb
161
+ - lib/open_classes/numeric/to_binary_html_table.rb
161
162
  - lib/open_classes/numeric/to_binary_table.rb
162
163
  - lib/open_classes/numeric/to_digit_table.rb
163
164
  - lib/open_classes/numeric/to_hex_table.rb
@@ -267,6 +268,7 @@ files:
267
268
  - spec/open_classes/numeric/dice_back_spec.rb
268
269
  - spec/open_classes/numeric/dozen_spec.rb
269
270
  - spec/open_classes/numeric/is_ascii_spec.rb
271
+ - spec/open_classes/numeric/to_binary_html_table_spec.rb
270
272
  - spec/open_classes/numeric/to_binary_table_spec.rb
271
273
  - spec/open_classes/numeric/to_digit_table_spec.rb
272
274
  - spec/open_classes/numeric/to_hex_table_spec.rb
@@ -397,6 +399,7 @@ test_files:
397
399
  - spec/open_classes/numeric/dice_back_spec.rb
398
400
  - spec/open_classes/numeric/dozen_spec.rb
399
401
  - spec/open_classes/numeric/is_ascii_spec.rb
402
+ - spec/open_classes/numeric/to_binary_html_table_spec.rb
400
403
  - spec/open_classes/numeric/to_binary_table_spec.rb
401
404
  - spec/open_classes/numeric/to_digit_table_spec.rb
402
405
  - spec/open_classes/numeric/to_hex_table_spec.rb