tbpgr_utils 0.0.77 → 0.0.78
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -0
- data/lib/open_classes/string/ascii_unicode_table.rb +40 -0
- data/lib/open_classes/string/justify_table.rb +16 -4
- data/lib/open_classes/string.rb +1 -0
- data/lib/tbpgr_utils/version.rb +1 -1
- data/spec/open_classes/string/ascii_unicode_table_spec.rb +48 -0
- data/spec/open_classes/string/justify_table_spec.rb +19 -1
- metadata +15 -12
data/README.md
CHANGED
@@ -101,6 +101,7 @@ Or install it yourself as:
|
|
101
101
|
|[TbpgrUtils Object#unless_guard](#objectunless_guard) |data type check for unless_guard |
|
102
102
|
|[SimpleTournament](#simpletournament) |simple tournament |
|
103
103
|
|[TbpgrUtils String#ascii1_other2_size](#stringascii1_other2_size) |count string size. ascii => count1, not ascii => count2 |
|
104
|
+
|[TbpgrUtils String#ascii_unicode_table](#stringascii_unicode_table) |get ascii_unicode_table |
|
104
105
|
|[TbpgrUtils String#comma_to_a](#stringcomma_to_a) |comma-format string to array |
|
105
106
|
|[TbpgrUtils String#hyphen_to_a](#stringhyphen_to_a) |hyphen-format string to array |
|
106
107
|
|[TbpgrUtils String#is_meta_variable?](#stringis_meta_variable) |is meta variable. |
|
@@ -2344,6 +2345,23 @@ require 'tbpgr_utils'
|
|
2344
2345
|
|
2345
2346
|
[back to list](#list)
|
2346
2347
|
|
2348
|
+
### String#ascii_unicode_table
|
2349
|
+
~~~ruby
|
2350
|
+
require 'tbpgr_utils'
|
2351
|
+
|
2352
|
+
'aあb'.ascii_unicode_table
|
2353
|
+
~~~
|
2354
|
+
|
2355
|
+
result
|
2356
|
+
~~~
|
2357
|
+
|char|ASCII|ascii2 |Unicode|
|
2358
|
+
| a | 97 |1100001| -- |
|
2359
|
+
| あ | -- | -- |0x3042 |
|
2360
|
+
| b | 98 |1100010| -- |
|
2361
|
+
~~~
|
2362
|
+
|
2363
|
+
[back to list](#list)
|
2364
|
+
|
2347
2365
|
### String#comma_to_a
|
2348
2366
|
space commma case
|
2349
2367
|
|
@@ -2739,6 +2757,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
|
|
2739
2757
|
https://github.com/tbpgr/tbpgr_utils_snippets
|
2740
2758
|
|
2741
2759
|
## History
|
2760
|
+
* version 0.0.78 : add String#ascii_unicode_table
|
2742
2761
|
* version 0.0.77 : add String#is_meta_variable?, Symbol#is_meta_variable?
|
2743
2762
|
* version 0.0.76 : add EvalHelper#attr_init_class_code, Numeric#is_ascii?, String#ascii1_other2_size
|
2744
2763
|
* version 0.0.75 : add Object#method_nameable?
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'open_classes/numeric/is_ascii'
|
3
|
+
require 'open_classes/string/justify_table'
|
4
|
+
require 'open_classes/string/ascii1_other2_size'
|
5
|
+
|
6
|
+
# String
|
7
|
+
class String
|
8
|
+
# get ascii_unicode_table
|
9
|
+
#
|
10
|
+
# === Example
|
11
|
+
#
|
12
|
+
# input
|
13
|
+
# 'aあb'
|
14
|
+
#
|
15
|
+
# result
|
16
|
+
#
|
17
|
+
# |char|ASCII|ascii2 |Unicode|
|
18
|
+
# | a | 97 |1100001| -- |
|
19
|
+
# | あ | -- | -- |0x3042 |
|
20
|
+
# | b | 98 |1100010| -- |
|
21
|
+
#
|
22
|
+
def ascii_unicode_table
|
23
|
+
ret = ['|char|ASCII|ascii2|Unicode|']
|
24
|
+
chars.each do |c|
|
25
|
+
each_ret = []
|
26
|
+
each_ret << "|#{c}"
|
27
|
+
if c.ord.is_ascii?
|
28
|
+
each_ret << c.ord
|
29
|
+
each_ret << c.ord.to_s(2)
|
30
|
+
each_ret << '--'
|
31
|
+
else
|
32
|
+
each_ret << '--'
|
33
|
+
each_ret << '--'
|
34
|
+
each_ret << "0x#{c.ord.to_s(16)}"
|
35
|
+
end
|
36
|
+
ret << each_ret.join('|') + '|'
|
37
|
+
end
|
38
|
+
(ret.join("\n") + "\n").justify_table(:center)
|
39
|
+
end
|
40
|
+
end
|
@@ -17,11 +17,11 @@ class String
|
|
17
17
|
# |eiichiro |oda |
|
18
18
|
# |akira |toriyama |
|
19
19
|
# |yusei |matsui |
|
20
|
-
def justify_table
|
20
|
+
def justify_table(position = :left)
|
21
21
|
return self if self.empty?
|
22
22
|
max_sizes = get_column_maxes
|
23
23
|
return self if max_sizes.nil?
|
24
|
-
justify_lines max_sizes
|
24
|
+
justify_lines max_sizes, position
|
25
25
|
end
|
26
26
|
|
27
27
|
private
|
@@ -36,20 +36,32 @@ class String
|
|
36
36
|
max_sizes
|
37
37
|
end
|
38
38
|
|
39
|
-
def justify_lines(max_sizes)
|
39
|
+
def justify_lines(max_sizes, position)
|
40
40
|
ret = []
|
41
41
|
each_line do |line|
|
42
42
|
columns = get_columuns(line)
|
43
43
|
line_ret = []
|
44
44
|
columns.each_with_index do |column, cnt|
|
45
45
|
diff = column.ascii1_other2_size - column.size
|
46
|
-
line_ret << column
|
46
|
+
line_ret << justified_column(column, max_sizes[cnt], diff, position)
|
47
47
|
end
|
48
48
|
ret << "|#{line_ret.join('|')}|"
|
49
49
|
end
|
50
50
|
ret.join("\n") + "\n"
|
51
51
|
end
|
52
52
|
|
53
|
+
def justified_column(column, max_size, diff, position)
|
54
|
+
pos = max_size - diff
|
55
|
+
case position
|
56
|
+
when :left
|
57
|
+
column.ljust(pos)
|
58
|
+
when :right
|
59
|
+
column.rjust(pos)
|
60
|
+
when :center
|
61
|
+
column.center(pos)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
53
65
|
def get_columuns(line)
|
54
66
|
line.split('|')[1..-2]
|
55
67
|
end
|
data/lib/open_classes/string.rb
CHANGED
data/lib/tbpgr_utils/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'open_classes/string/ascii_unicode_table'
|
4
|
+
|
5
|
+
describe String do
|
6
|
+
context :ascii_unicode_table do
|
7
|
+
cases = [
|
8
|
+
{
|
9
|
+
case_no: 1,
|
10
|
+
case_title: '> case',
|
11
|
+
input: 'aあb',
|
12
|
+
expected: <<-EOS
|
13
|
+
|char|ASCII|ascii2 |Unicode|
|
14
|
+
| a | 97 |1100001| -- |
|
15
|
+
| あ | -- | -- |0x3042 |
|
16
|
+
| b | 98 |1100010| -- |
|
17
|
+
EOS
|
18
|
+
},
|
19
|
+
]
|
20
|
+
|
21
|
+
cases.each do |c|
|
22
|
+
it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
|
23
|
+
begin
|
24
|
+
case_before c
|
25
|
+
|
26
|
+
# -- given --
|
27
|
+
# nothing
|
28
|
+
|
29
|
+
# -- when --
|
30
|
+
actual = c[:input].ascii_unicode_table
|
31
|
+
|
32
|
+
# -- then --
|
33
|
+
expect(actual).to eq(c[:expected])
|
34
|
+
ensure
|
35
|
+
case_after c
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def case_before(c)
|
40
|
+
# implement each case before
|
41
|
+
end
|
42
|
+
|
43
|
+
def case_after(c)
|
44
|
+
# implement each case after
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -38,6 +38,13 @@ csv_column2_1, csv_column2_2
|
|
38
38
|
|yusei |matsui |
|
39
39
|
EOS
|
40
40
|
|
41
|
+
SAMPLE_JUSTIFIED_TABLE5 = <<-EOS
|
42
|
+
|* firstあ name|* family いいname|
|
43
|
+
| eiichiro| oda|
|
44
|
+
| akira| toriyama|
|
45
|
+
| yusei| matsui|
|
46
|
+
EOS
|
47
|
+
|
41
48
|
cases = [
|
42
49
|
{
|
43
50
|
case_no: 1,
|
@@ -63,6 +70,13 @@ csv_column2_1, csv_column2_2
|
|
63
70
|
input: SAMPLE_TABLE4,
|
64
71
|
expected: SAMPLE_JUSTIFIED_TABLE4,
|
65
72
|
},
|
73
|
+
{
|
74
|
+
case_no: 5,
|
75
|
+
case_title: 'ascii/other code mix valid justify case(right)',
|
76
|
+
input: SAMPLE_TABLE4,
|
77
|
+
position: :right,
|
78
|
+
expected: SAMPLE_JUSTIFIED_TABLE5,
|
79
|
+
},
|
66
80
|
]
|
67
81
|
|
68
82
|
cases.each do |c|
|
@@ -74,7 +88,11 @@ csv_column2_1, csv_column2_2
|
|
74
88
|
# nothing
|
75
89
|
|
76
90
|
# -- when --
|
77
|
-
|
91
|
+
if (c[:position])
|
92
|
+
actual = c[:input].justify_table c[:position]
|
93
|
+
else
|
94
|
+
actual = c[:input].justify_table
|
95
|
+
end
|
78
96
|
|
79
97
|
# -- then --
|
80
98
|
expect(actual).to eq(c[:expected])
|
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.78
|
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-03-
|
12
|
+
date: 2014-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
|
-
requirement: &
|
16
|
+
requirement: &22382532 !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: *22382532
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &22382244 !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: *22382244
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &22382016 !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: *22382016
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &22381692 !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: *22381692
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &22381392 !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: *22381392
|
69
69
|
description: Utilities
|
70
70
|
email:
|
71
71
|
- tbpgr@tbpgr.jp
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/open_classes/object/to_bool.rb
|
158
158
|
- lib/open_classes/string.rb
|
159
159
|
- lib/open_classes/string/ascii1_other2_size.rb
|
160
|
+
- lib/open_classes/string/ascii_unicode_table.rb
|
160
161
|
- lib/open_classes/string/comma_to_a.rb
|
161
162
|
- lib/open_classes/string/heading_helper.rb
|
162
163
|
- lib/open_classes/string/hyphen_to_a.rb
|
@@ -246,6 +247,7 @@ files:
|
|
246
247
|
- spec/open_classes/object/null_spec.rb
|
247
248
|
- spec/open_classes/object/to_bool_spec.rb
|
248
249
|
- spec/open_classes/string/ascii1_other2_size_spec.rb
|
250
|
+
- spec/open_classes/string/ascii_unicode_table_spec.rb
|
249
251
|
- spec/open_classes/string/comma_to_a_spec.rb
|
250
252
|
- spec/open_classes/string/hyphen_to_a_spec.rb
|
251
253
|
- spec/open_classes/string/is_meta_variable_spec.rb
|
@@ -358,6 +360,7 @@ test_files:
|
|
358
360
|
- spec/open_classes/object/null_spec.rb
|
359
361
|
- spec/open_classes/object/to_bool_spec.rb
|
360
362
|
- spec/open_classes/string/ascii1_other2_size_spec.rb
|
363
|
+
- spec/open_classes/string/ascii_unicode_table_spec.rb
|
361
364
|
- spec/open_classes/string/comma_to_a_spec.rb
|
362
365
|
- spec/open_classes/string/hyphen_to_a_spec.rb
|
363
366
|
- spec/open_classes/string/is_meta_variable_spec.rb
|