tbpgr_utils 0.0.96 → 0.0.97
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.
data/README.md
CHANGED
@@ -100,6 +100,7 @@ Or install it yourself as:
|
|
100
100
|
|[TbpgrUtils Numeric#is_ascii?](#numericis_ascii) |get is_ascii number |
|
101
101
|
|[TbpgrUtils Numeric to_binary_html_table](#numeric-to_binary_html_table) |binary html table |
|
102
102
|
|[TbpgrUtils Numeric to_binary_table](#numeric-to_binary_table) |binary table |
|
103
|
+
|[TbpgrUtils Numeric to_digit_html_table](#numeric-to_digit_html_table) |digit html table |
|
103
104
|
|[TbpgrUtils Numeric to_digit_table](#numeric-to_digit_table) |digit table |
|
104
105
|
|[TbpgrUtils Numeric to_hex_table](#numeric-to_hex_table) |hex table |
|
105
106
|
|[TbpgrUtils Numeric to_oct_table](#numeric-to_oct_table) |oct table |
|
@@ -2427,6 +2428,39 @@ result
|
|
2427
2428
|
|
2428
2429
|
[back to list](#list)
|
2429
2430
|
|
2431
|
+
### Numeric to_digit_html_table
|
2432
|
+
255 to 256 case
|
2433
|
+
~~~ruby
|
2434
|
+
require 'tbpgr_utils'
|
2435
|
+
Numeric.to_digit_html_table(255, 256)
|
2436
|
+
~~~
|
2437
|
+
|
2438
|
+
result
|
2439
|
+
~~~html
|
2440
|
+
<table>
|
2441
|
+
<tr>
|
2442
|
+
<th>10digit</th>
|
2443
|
+
<th>2digit</th>
|
2444
|
+
<th>8digit</th>
|
2445
|
+
<th>16digit</th>
|
2446
|
+
</tr>
|
2447
|
+
<tr>
|
2448
|
+
<td>255</td>
|
2449
|
+
<td>0000000011111111</td>
|
2450
|
+
<td>377</td>
|
2451
|
+
<td>00ff</td>
|
2452
|
+
</tr>
|
2453
|
+
<tr>
|
2454
|
+
<td>256</td>
|
2455
|
+
<td>0000000100000000</td>
|
2456
|
+
<td>400</td>
|
2457
|
+
<td>0100</td>
|
2458
|
+
</tr>
|
2459
|
+
</table>
|
2460
|
+
~~~
|
2461
|
+
|
2462
|
+
[back to list](#list)
|
2463
|
+
|
2430
2464
|
### Numeric to_digit_table
|
2431
2465
|
255 to 256 case
|
2432
2466
|
~~~ruby
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Numeric
|
4
|
+
class Numeric
|
5
|
+
# return is digit html table
|
6
|
+
#
|
7
|
+
# ==== Examples
|
8
|
+
#
|
9
|
+
# 255 to 256 case
|
10
|
+
#
|
11
|
+
# Numeric.to_digit_html_table(255, 256)
|
12
|
+
#
|
13
|
+
# result
|
14
|
+
#
|
15
|
+
# <table>
|
16
|
+
# <tr>
|
17
|
+
# <th>10digit</th>
|
18
|
+
# <th>2digit</th>
|
19
|
+
# <th>8digit</th>
|
20
|
+
# <th>16digit</th>
|
21
|
+
# </tr>
|
22
|
+
# <tr>
|
23
|
+
# <td>255</td>
|
24
|
+
# <td>0000000011111111</td>
|
25
|
+
# <td>377</td>
|
26
|
+
# <td>00ff</td>
|
27
|
+
# </tr>
|
28
|
+
# <tr>
|
29
|
+
# <td>256</td>
|
30
|
+
# <td>0000000100000000</td>
|
31
|
+
# <td>400</td>
|
32
|
+
# <td>0100</td>
|
33
|
+
# </tr>
|
34
|
+
# </table>
|
35
|
+
#
|
36
|
+
def self.to_digit_html_table(from = 1, to = 10)
|
37
|
+
ret = []
|
38
|
+
binary_size = to.to_s(2).size - 1
|
39
|
+
binary_pad = (binary_size / 8 + 1) * 8
|
40
|
+
oct_size = to.to_s(8).size
|
41
|
+
hex_size = to.to_s(16).size - 1
|
42
|
+
hex_pad = (hex_size / 4 + 1) * 4
|
43
|
+
ret << "<table>\n <tr>\n <th>10digit</th>\n <th>2digit</th>\n <th>8digit</th>\n <th>16digit</th>\n </tr>"
|
44
|
+
(from..to).each { |i|ret << " <tr>\n <td>#{i}</td>\n <td>#{i.to_s(2).rjust(binary_pad, '0')}</td>\n <td>#{i.to_s(8).rjust(oct_size, '0')}</td>\n <td>#{i.to_s(16).rjust(hex_pad, '0')}</td>\n </tr>" }
|
45
|
+
ret.join("\n") + "\n</table>\n"
|
46
|
+
end
|
47
|
+
end
|
data/lib/open_classes/numeric.rb
CHANGED
@@ -4,6 +4,7 @@ require 'open_classes/numeric/dozen'
|
|
4
4
|
require 'open_classes/numeric/is_ascii'
|
5
5
|
require 'open_classes/numeric/to_binary_table'
|
6
6
|
require 'open_classes/numeric/to_binary_html_table'
|
7
|
+
require 'open_classes/numeric/to_digit_html_table'
|
7
8
|
require 'open_classes/numeric/to_digit_table'
|
8
9
|
require 'open_classes/numeric/to_hex_table'
|
9
10
|
require 'open_classes/numeric/to_oct_table'
|
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'tbpgr_utils'
|
4
|
+
|
5
|
+
describe Numeric do
|
6
|
+
context :to_digit_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
|
+
<th>8digit</th>
|
19
|
+
<th>16digit</th>
|
20
|
+
</tr>
|
21
|
+
<tr>
|
22
|
+
<td>1</td>
|
23
|
+
<td>00000001</td>
|
24
|
+
<td>1</td>
|
25
|
+
<td>0001</td>
|
26
|
+
</tr>
|
27
|
+
<tr>
|
28
|
+
<td>2</td>
|
29
|
+
<td>00000010</td>
|
30
|
+
<td>2</td>
|
31
|
+
<td>0002</td>
|
32
|
+
</tr>
|
33
|
+
<tr>
|
34
|
+
<td>3</td>
|
35
|
+
<td>00000011</td>
|
36
|
+
<td>3</td>
|
37
|
+
<td>0003</td>
|
38
|
+
</tr>
|
39
|
+
</table>
|
40
|
+
EOS
|
41
|
+
},
|
42
|
+
{
|
43
|
+
case_no: 2,
|
44
|
+
case_title: '255-256 case',
|
45
|
+
from: 255,
|
46
|
+
to: 256,
|
47
|
+
expected: <<-EOS
|
48
|
+
<table>
|
49
|
+
<tr>
|
50
|
+
<th>10digit</th>
|
51
|
+
<th>2digit</th>
|
52
|
+
<th>8digit</th>
|
53
|
+
<th>16digit</th>
|
54
|
+
</tr>
|
55
|
+
<tr>
|
56
|
+
<td>255</td>
|
57
|
+
<td>0000000011111111</td>
|
58
|
+
<td>377</td>
|
59
|
+
<td>00ff</td>
|
60
|
+
</tr>
|
61
|
+
<tr>
|
62
|
+
<td>256</td>
|
63
|
+
<td>0000000100000000</td>
|
64
|
+
<td>400</td>
|
65
|
+
<td>0100</td>
|
66
|
+
</tr>
|
67
|
+
</table>
|
68
|
+
EOS
|
69
|
+
},
|
70
|
+
]
|
71
|
+
|
72
|
+
cases.each do |c|
|
73
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
74
|
+
begin
|
75
|
+
case_before c
|
76
|
+
|
77
|
+
# -- given --
|
78
|
+
# nothing
|
79
|
+
|
80
|
+
# -- when --
|
81
|
+
actual = Numeric.to_digit_html_table(c[:from], c[:to])
|
82
|
+
|
83
|
+
# -- then --
|
84
|
+
expect(actual).to eq(c[:expected])
|
85
|
+
ensure
|
86
|
+
case_after c
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def case_before(c)
|
91
|
+
# implement each case before
|
92
|
+
end
|
93
|
+
|
94
|
+
def case_after(c)
|
95
|
+
# implement each case after
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
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.
|
4
|
+
version: 0.0.97
|
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
|
+
date: 2014-04-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &2698332 !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: *
|
24
|
+
version_requirements: *2698332
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &3202644 !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: *
|
35
|
+
version_requirements: *3202644
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &3217116 !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: *
|
46
|
+
version_requirements: *3217116
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &3225036 !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: *
|
57
|
+
version_requirements: *3225036
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &3222804 !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: *
|
68
|
+
version_requirements: *3222804
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- lib/open_classes/numeric/is_ascii.rb
|
161
161
|
- lib/open_classes/numeric/to_binary_html_table.rb
|
162
162
|
- lib/open_classes/numeric/to_binary_table.rb
|
163
|
+
- lib/open_classes/numeric/to_digit_html_table.rb
|
163
164
|
- lib/open_classes/numeric/to_digit_table.rb
|
164
165
|
- lib/open_classes/numeric/to_hex_table.rb
|
165
166
|
- lib/open_classes/numeric/to_oct_table.rb
|
@@ -270,6 +271,7 @@ files:
|
|
270
271
|
- spec/open_classes/numeric/is_ascii_spec.rb
|
271
272
|
- spec/open_classes/numeric/to_binary_html_table_spec.rb
|
272
273
|
- spec/open_classes/numeric/to_binary_table_spec.rb
|
274
|
+
- spec/open_classes/numeric/to_digit_html_table_spec.rb
|
273
275
|
- spec/open_classes/numeric/to_digit_table_spec.rb
|
274
276
|
- spec/open_classes/numeric/to_hex_table_spec.rb
|
275
277
|
- spec/open_classes/numeric/to_oct_table_spec.rb
|
@@ -401,6 +403,7 @@ test_files:
|
|
401
403
|
- spec/open_classes/numeric/is_ascii_spec.rb
|
402
404
|
- spec/open_classes/numeric/to_binary_html_table_spec.rb
|
403
405
|
- spec/open_classes/numeric/to_binary_table_spec.rb
|
406
|
+
- spec/open_classes/numeric/to_digit_html_table_spec.rb
|
404
407
|
- spec/open_classes/numeric/to_digit_table_spec.rb
|
405
408
|
- spec/open_classes/numeric/to_hex_table_spec.rb
|
406
409
|
- spec/open_classes/numeric/to_oct_table_spec.rb
|