mb_string 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +1 -1
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/lib/mb_string.rb +2 -2
- data/lib/mb_string/core_ext/string.rb +34 -34
- data/lib/mb_string/version.rb +1 -1
- data/mb_string.gemspec +17 -17
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d144aa62bc361807eea6cdc3b4d8a55575ac6a88
|
4
|
+
data.tar.gz: ebca0a0086acde2f28949c7fa2bb474b1ca986e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18ab3b46aa2eefcfc8a112158de57e6707c58d24d8dcba2323b71af716f243cf236120de850ef13cadf510f78f2d990f3d276e37d5345bee3a5c8202c96e31ad
|
7
|
+
data.tar.gz: 251922d6f5a8cbbc3dd0709a2118697b7d416e85bef0a9b11b0b7885e142be2ba4a729cf926903968ac02bf50e5f365b42ec07715c30410c74d37d06bd3d3047
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mb_string"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require 'mb_string'
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require "irb"
|
14
14
|
IRB.start
|
data/lib/mb_string.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require "unicode/display_width"
|
2
2
|
class String
|
3
|
-
def mb_ljust(width, pad_str =
|
3
|
+
def mb_ljust(width, pad_str = " ")
|
4
4
|
return ljust(width, pad_str) if ascii_only? && pad_str.ascii_only?
|
5
5
|
mb_execute(width) do |pad_size|
|
6
6
|
self + mb_build_padding(pad_size, pad_str)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
def mb_rjust(width, pad_str =
|
10
|
+
def mb_rjust(width, pad_str = " ")
|
11
11
|
return rjust(width, pad_str) if ascii_only? && pad_str.ascii_only?
|
12
12
|
mb_execute(width) do |pad_size|
|
13
13
|
mb_build_padding(pad_size, pad_str, is_append_right: false) + self
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def mb_center(width, pad_str =
|
17
|
+
def mb_center(width, pad_str = " ")
|
18
18
|
return center(width, pad_str) if ascii_only? && pad_str.ascii_only?
|
19
19
|
mb_execute(width) do |pad_size|
|
20
20
|
left_pad_size = pad_size / 2
|
@@ -30,11 +30,11 @@ class String
|
|
30
30
|
def mb_truncate(truncate_at, options = {})
|
31
31
|
return dup unless display_width > truncate_at
|
32
32
|
|
33
|
-
omission = options[:omission] ||
|
33
|
+
omission = options[:omission] || "..."
|
34
34
|
length_with_room_for_omission = truncate_at - omission.display_width
|
35
35
|
|
36
36
|
size = 0
|
37
|
-
slice =
|
37
|
+
slice = ""
|
38
38
|
each_char do |c|
|
39
39
|
char_size = c.display_width
|
40
40
|
if size + char_size > length_with_room_for_omission
|
@@ -49,39 +49,39 @@ class String
|
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def mb_execute(width)
|
53
|
+
pad_size = [width - display_width, 0].max
|
54
|
+
return self if pad_size.zero?
|
55
|
+
yield(pad_size)
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
def mb_build_padding(pad_size, pad_str, is_append_right: true)
|
59
|
+
pad_display_width = pad_str.display_width
|
60
|
+
pad_num, mod = pad_size.divmod(pad_display_width)
|
61
|
+
padding = pad_str * pad_num
|
62
|
+
if mod > 0
|
63
|
+
padding = mb_tweak_reminder(pad_str, mod, padding)
|
64
|
+
padding = append_reminder_space(padding, is_append_right) if pad_size > padding.display_width
|
65
|
+
end
|
66
|
+
padding
|
65
67
|
end
|
66
|
-
padding
|
67
|
-
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
def mb_tweak_reminder(pad_str, mod, padding)
|
70
|
+
pad_str.each_char do |c|
|
71
|
+
char_display_width = c.display_width
|
72
|
+
if mod >= char_display_width
|
73
|
+
padding << c
|
74
|
+
mod -= char_display_width
|
75
|
+
end
|
75
76
|
end
|
77
|
+
padding
|
76
78
|
end
|
77
|
-
padding
|
78
|
-
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
80
|
+
def append_reminder_space(padding, is_append_right)
|
81
|
+
if is_append_right
|
82
|
+
padding + " "
|
83
|
+
else
|
84
|
+
" " + padding
|
85
|
+
end
|
85
86
|
end
|
86
|
-
end
|
87
87
|
end
|
data/lib/mb_string/version.rb
CHANGED
data/mb_string.gemspec
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "mb_string/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = "mb_string"
|
8
8
|
spec.version = MbString::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ["rochefort"]
|
10
|
+
spec.email = ["terasawan@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary =
|
12
|
+
spec.summary = "You can use mb_ljust, mb_rjust, mb_center for multibyte strings."
|
13
13
|
spec.description = spec.summary
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
14
|
+
spec.homepage = "https://github.com/rochefort/mb_string"
|
15
|
+
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir =
|
18
|
+
spec.bindir = "exe"
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
-
spec.require_paths = [
|
20
|
+
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency
|
22
|
+
spec.add_dependency "unicode-display_width", "~> 1.1.1"
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 11.3.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.5.0"
|
27
|
+
spec.add_development_dependency "simplecov", "~> 0.12.0"
|
28
28
|
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
29
|
+
spec.add_development_dependency "coveralls", "~> 0.8.15"
|
30
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
31
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mb_string
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rochefort
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode-display_width
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.1.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,56 +44,56 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 11.
|
47
|
+
version: 11.3.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 11.
|
54
|
+
version: 11.3.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.
|
61
|
+
version: 3.5.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.
|
68
|
+
version: 3.5.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.12.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.12.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: coveralls
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.8.15
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 0.8.15
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: codeclimate-test-reporter
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
152
|
+
rubygems_version: 2.6.6
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: You can use mb_ljust, mb_rjust, mb_center for multibyte strings.
|