slim_string 1.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/ChangeLog +10 -0
- data/LICENSE.txt +20 -0
- data/Makefile +24 -0
- data/README.en.rdoc +81 -0
- data/Rakefile +9 -0
- data/lib/slim_string.rb +108 -0
- data/slim_string.gemspec +59 -0
- data/test/test_slim_string.rb +78 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7809507e7ec9cd436f92b3a3f90150994eec48c70925fe1a971e97a53867d32b
|
4
|
+
data.tar.gz: d74f135e5475123d3d4c60b0e35dbd641fe109cdcb7f5ee2cbaaabcb6b76b178
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 38b24b2d3841629ec0f1c3d24bd7a18a05f7b00b44d69501ea1fbb1b6c410b2d6f615c966132e31224ba39c953696ed71ca7781dc889f3cc4429be6923ad6501
|
7
|
+
data.tar.gz: 44b0d9508421a804730a59a32e31bf6b2631b51d3f34ccda833a6966f1299f395d3e267ba7a1e780e3a5f60127a9630b0b38268959f9b8f3442c113eda91f0ef
|
data/.gitignore
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
/vendor/bundle
|
10
|
+
|
11
|
+
# Ignore all logfiles and tempfiles.
|
12
|
+
/log/*
|
13
|
+
/tmp/*
|
14
|
+
!/log/.keep
|
15
|
+
!/tmp/.keep
|
16
|
+
|
17
|
+
.rbenv-version
|
18
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
19
|
+
.rvmrc
|
20
|
+
|
21
|
+
/node_modules
|
22
|
+
/yarn-error.log
|
23
|
+
|
24
|
+
.byebug_history
|
25
|
+
|
26
|
+
*.[oa]
|
27
|
+
*.so
|
28
|
+
*~
|
29
|
+
*.nogem
|
30
|
+
*nogem.*
|
31
|
+
*.bak
|
32
|
+
*.BAK
|
33
|
+
*.backup
|
34
|
+
*.org
|
35
|
+
*.orig
|
36
|
+
*.elc
|
37
|
+
*.pyc
|
38
|
+
\#*\#
|
39
|
+
|
40
|
+
# Elastic Beanstalk Files
|
41
|
+
.elasticbeanstalk/*
|
42
|
+
!.elasticbeanstalk/*.cfg.yml
|
43
|
+
!.elasticbeanstalk/*.global.yml
|
44
|
+
|
45
|
+
# yard
|
46
|
+
*.yardoc
|
47
|
+
|
48
|
+
# Ruby Gem doc
|
49
|
+
*.gem
|
50
|
+
doc/*
|
51
|
+
|
data/ChangeLog
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012-2018 Scott Chacon and others
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Makefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
ALL =
|
2
|
+
|
3
|
+
objs =
|
4
|
+
|
5
|
+
.SUFFIXES: .so .o .c .f
|
6
|
+
|
7
|
+
#.o.so:
|
8
|
+
# ${LD} ${LFLAGS} -o $@ $< ${LINK_LIB}
|
9
|
+
|
10
|
+
all: ${ALL}
|
11
|
+
|
12
|
+
|
13
|
+
.PHONY: clean test doc
|
14
|
+
clean:
|
15
|
+
$(RM) bin/*~
|
16
|
+
|
17
|
+
## You may need RUBYLIB=`pwd`/lib:$RUBYLIB
|
18
|
+
test:
|
19
|
+
rake test
|
20
|
+
|
21
|
+
## yard2md_afterclean in Gem plain_text https://rubygems.org/gems/plain_text
|
22
|
+
doc:
|
23
|
+
yard doc; [[ -x ".github" && ( "README.en.rdoc" -nt ".github/README.md" ) ]] && ( ruby -r rdoc -e 'puts RDoc::Markup::ToMarkdown.new.convert ARGF.read' < README.en.rdoc | yard2md_afterclean > .github/README.md.$$ && ( mv -f .github/README.md.$$ .github/README.md && echo ".github/README.md is updated." ) || ( echo "ERROR: failed to create .github/README.md" >&2 ) ) || exit 0
|
24
|
+
|
data/README.en.rdoc
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
|
2
|
+
= SlimString - Ruby method to slim down UTF-8 character strings
|
3
|
+
|
4
|
+
== Summary
|
5
|
+
|
6
|
+
Module {SlimString} contains a single method of the same (but
|
7
|
+
snake-case) name +SlimString#slim_string+, which offers functionality
|
8
|
+
to "slim down" character String, such as truncating extra spaces with many
|
9
|
+
options you can select.
|
10
|
+
It fully takes into account *UTF-8 characters* like CJK Zenkaku spaces.
|
11
|
+
|
12
|
+
The full package of this class is found in
|
13
|
+
{SlimString Ruby Gems page}[http://rubygems.org/gems/slim_string]
|
14
|
+
(with document created from source annotation with yard) and
|
15
|
+
in {Github}[https://github.com/masasakano/slim_string]
|
16
|
+
|
17
|
+
== Description
|
18
|
+
|
19
|
+
=== How to use it?
|
20
|
+
|
21
|
+
1. Simply call it in a full path (it is extended and so you can call it in this way.
|
22
|
+
|
23
|
+
SlimString.slim_string("\nabc\n\n", strip: false) # => "\nabc"
|
24
|
+
2. Include in your class/module (or top level), and you can use it without the module name.
|
25
|
+
|
26
|
+
include SlimString
|
27
|
+
slim_string("\nabc\n\n", strip: false) # => "\nabc"
|
28
|
+
3. Include it in +String+ class like and you can use it as an instance method.
|
29
|
+
|
30
|
+
class String
|
31
|
+
include SlimString
|
32
|
+
end
|
33
|
+
|
34
|
+
"\nabc\n\n".slim_string(trim: false) # => "\nabc"
|
35
|
+
|
36
|
+
=== Options
|
37
|
+
|
38
|
+
All options (aka, arguments) are Boolean.
|
39
|
+
The given string is processed in this order regardless how you do or
|
40
|
+
do not specify them.
|
41
|
+
|
42
|
+
+delete_newlines+:: (Def: false) Delete all new lines (\f\n\r\v) (maybe useful for Japanese text, unless more than 1 alphabet word are split across 2 lines).
|
43
|
+
+convert_spaces+:: (Def: false) Convert any sort of spaces (including new lines) into an ASCII space.
|
44
|
+
+convert_blanks+:: (Def: true) Convert all blanks (=spaces except kind of new lines) into an ASCII space.
|
45
|
+
+truncate_spaces+:: (Def: false) Truncate any consecutive spaces into one.
|
46
|
+
+truncate_blanks+:: (Def: true) Truncate any consecutive blanks into (the last) one.
|
47
|
+
+truncate_triple_newlines+:: (Def: false) Truncate 3 or more consecutive newlines into 2.
|
48
|
+
+delete_blanks+:: (Def: false) Simply delete all blanks excluding new lines (n.b., "a top" and "atop" are regarded identical.
|
49
|
+
+strip+:: (Def: true) Ruby strip; strip spaces including new lines at the head and tail.
|
50
|
+
+trim_blanks+:: (Def: false) strip blanks (but new lines) at the tail.
|
51
|
+
+trim+:: (Def: true) Trim the tail to strip any spaces including new lines at the tail.
|
52
|
+
|
53
|
+
== Install
|
54
|
+
|
55
|
+
This script requires {Ruby}[http://www.ruby-lang.org] Version 2.0
|
56
|
+
or above. Also, all this library depends on {SubObject (sub_object)}[https://rubygems.org/gems/sub_object], which you can
|
57
|
+
find in RubyGems.
|
58
|
+
|
59
|
+
== Developer's note
|
60
|
+
|
61
|
+
The source code is maintained also in
|
62
|
+
{Github}[https://github.com/masasakano/slim_string] with no intuitive
|
63
|
+
interface for annotation but with easily-browsable {ChangeLog}[https://github.com/masasakano/slim_string/blob/master/ChangeLog]
|
64
|
+
|
65
|
+
=== Tests
|
66
|
+
|
67
|
+
The Ruby codes under the directory <tt>test/</tt> are the test scripts.
|
68
|
+
You can run them from the top directory as <tt>ruby test/test_****.rb</tt>
|
69
|
+
or simply run <tt>make test</tt> or <tt>rake test</tt>.
|
70
|
+
|
71
|
+
== Known bugs and Todo items
|
72
|
+
|
73
|
+
* None
|
74
|
+
|
75
|
+
|
76
|
+
== Copyright
|
77
|
+
|
78
|
+
Author:: Masa Sakano < info a_t wisebabel dot com >
|
79
|
+
Versions:: The versions of this package follow Semantic Versioning (2.0.0) http://semver.org/
|
80
|
+
License:: MIT
|
81
|
+
|
data/Rakefile
ADDED
data/lib/slim_string.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
# A module containing a method to slim down a UTF-8 String
|
4
|
+
#
|
5
|
+
# It handles UTF8 characters, such as CJK (Zenkaku) spaces
|
6
|
+
# and offers many choices how to slim down a character string.
|
7
|
+
#
|
8
|
+
# There are 3 ways to use the method {SlimString#slim_string}
|
9
|
+
#
|
10
|
+
# (1) Simply call it in a full path
|
11
|
+
# SlimString.slim_string("abc", trim: false)
|
12
|
+
# (2) Include in your class/module (or top level), and you can
|
13
|
+
# use it like: slim_string("abc", trim: false)
|
14
|
+
# (3) Include it in String class like and you can used it like
|
15
|
+
# an instance method.
|
16
|
+
# class String
|
17
|
+
# include SlimString
|
18
|
+
# end
|
19
|
+
# "abc".slim_string(trim: false)
|
20
|
+
#
|
21
|
+
module SlimString
|
22
|
+
|
23
|
+
# Default options of operations for {#slim_string}, which processes
|
24
|
+
# in this order if specified.
|
25
|
+
DEF_SLIM_OPTIONS = {
|
26
|
+
:delete_newlines => false, # Delete all new lines (\f\n\r\v) (useful for Japanese text, unless more than 1 alphabet word are split across 2 lines).
|
27
|
+
:convert_spaces => false, # Convert any sort of spaces (including new lines) into an ASCII space.
|
28
|
+
:convert_blanks => true, # Convert all blanks (=spaces except kind of new lines) into an ASCII space.
|
29
|
+
:truncate_spaces => false, # Truncate any consecutive spaces into one.
|
30
|
+
:truncate_blanks => true, # Truncate any consecutive blanks into (the last) one.
|
31
|
+
:truncate_triple_newlines => false, # Truncate 3 or more consecutive newlines into 2.
|
32
|
+
:delete_blanks => false, # Simply delete all blanks excluding new lines (n.b., "a top" and "atop" are regarded identical.
|
33
|
+
:strip => true, # Ruby strip; strip spaces including new lines at the head and tail.
|
34
|
+
:trim_blanks => false, # strip blanks (but new lines) at the tail.
|
35
|
+
:trim => true, # Trim the tail to strip any spaces including new lines at the tail.
|
36
|
+
}
|
37
|
+
|
38
|
+
# Returns a slimmed down string
|
39
|
+
#
|
40
|
+
# @option str [String] Mandatory unless you use it as an instance
|
41
|
+
# method of String class.
|
42
|
+
# @param delete_newlines: [Boolean] (Def: false) Delete all new lines
|
43
|
+
# (\f\n\r\v) (maybe useful for Japanese text, unless more than 1
|
44
|
+
# alphabet word are split across 2 lines).
|
45
|
+
# @param convert_spaces: [Boolean] (Def: false) Convert any sort of
|
46
|
+
# spaces (including new lines) into an ASCII space.
|
47
|
+
# @param convert_blanks: [Boolean] (Def: true) Convert all blanks
|
48
|
+
# (=spaces except kind of new lines) into an ASCII space.
|
49
|
+
# @param truncate_spaces: [Boolean] (Def: false) Truncate any
|
50
|
+
# consecutive spaces into one.
|
51
|
+
# @param truncate_blanks: [Boolean] (Def: true) Truncate any
|
52
|
+
# consecutive blanks into (the last) one.
|
53
|
+
# @param truncate_triple_newlines: [Boolean] (Def: false) Truncate
|
54
|
+
# 3 or more consecutive newlines into 2.
|
55
|
+
# @param delete_blanks: [Boolean] (Def: false) Simply delete all blanks
|
56
|
+
# excluding new lines (n.b., "a top" and "atop" are regarded identical.
|
57
|
+
# @param strip: [Boolean] (Def: true) Ruby strip; strip spaces
|
58
|
+
# including new lines at the head and tail.
|
59
|
+
# @param trim_blanks: [Boolean] (Def: false) strip blanks (but new lines)
|
60
|
+
# at the tail.
|
61
|
+
# @param trim: [Boolean] (Def: true) Trim the tail to strip any spaces
|
62
|
+
# including new lines at the tail.
|
63
|
+
# @return [String]
|
64
|
+
# @raise [ArgumentError] Unless you include this module from
|
65
|
+
# String class and use it as an instance method, the first
|
66
|
+
# argument is mandatory.
|
67
|
+
def slim_string(str=nil, **opts)
|
68
|
+
begin
|
69
|
+
ret = (str || self).dup
|
70
|
+
rescue NoMethodError
|
71
|
+
raise ArgumentError, 'first argument is mandatory and must be String-like.'
|
72
|
+
end
|
73
|
+
|
74
|
+
DEF_SLIM_OPTIONS.merge(opts).each_pair do |ek, tf|
|
75
|
+
next if !tf
|
76
|
+
case ek
|
77
|
+
when :delete_newlines
|
78
|
+
ret.tr! "\f\n\r\v", "" # ASCII Formfeed (FF), Linefeed (LF), Carriage Return (CR), Vertical Tab (VT)
|
79
|
+
when :convert_spaces
|
80
|
+
ret.gsub!(/[[:space:]]/, ' ')
|
81
|
+
when :convert_blanks
|
82
|
+
ret.gsub!(/[[:blank:]]/, ' ')
|
83
|
+
when :truncate_spaces
|
84
|
+
ret.gsub!(/([[:space:]])+/, '\1')
|
85
|
+
when :truncate_blanks
|
86
|
+
ret.gsub!(/([[:blank:]])+/, '\1')
|
87
|
+
when :truncate_triple_newlines
|
88
|
+
ret.gsub!(/([\f\n\r\v]){3,}/, '\1\1')
|
89
|
+
when :delete_blanks
|
90
|
+
ret.gsub!(/[[:blank:]]+/, "")
|
91
|
+
when :strip
|
92
|
+
ret.strip!
|
93
|
+
when :trim_blanks
|
94
|
+
ret.gsub!(/[[:blank:]]+\z/, "")
|
95
|
+
when :trim
|
96
|
+
ret.gsub!(/([[:space:]])+\z/, "")
|
97
|
+
else
|
98
|
+
raise ArgumentError, 'Invalid optional argument: '+tf.inspect
|
99
|
+
end
|
100
|
+
end
|
101
|
+
ret
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
module SlimString
|
106
|
+
extend self
|
107
|
+
end
|
108
|
+
|
data/slim_string.gemspec
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'slim_string'.sub(/.*/){|c| (c == File.basename(Dir.pwd)) ? c : raise("ERROR: s.name=(#{c}) in gemspec seems wrong!")}
|
8
|
+
s.version = "1.0.1".sub(/.*/){|c| fs = Dir.glob('changelog{,.*}', File::FNM_CASEFOLD); raise('More than one ChangeLog exist!') if fs.size > 1; warn("WARNING: Version(s.version=#{c}) already exists in #{fs[0]} - ok?") if fs.size == 1 && !IO.readlines(fs[0]).grep(/^\(Version: #{Regexp.quote c}\)$/).empty? ; c } # n.b., In macOS, changelog and ChangeLog are identical in default.
|
9
|
+
# s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
# s.bindir = 'bin'
|
11
|
+
# %w(slim_string).each do |f|
|
12
|
+
# path = s.bindir+'/'+f
|
13
|
+
# File.executable?(path) ? s.executables << f : raise("ERROR: Executable (#{path}) is not executable!")
|
14
|
+
# end
|
15
|
+
s.authors = ["Masa Sakano"]
|
16
|
+
s.date = %q{2021-07-04}.sub(/.*/){|c| (Date.parse(c) == Date.today) ? c : raise("ERROR: s.date=(#{c}) is not today!")}
|
17
|
+
s.summary = %q{Slim down a UTF-8 String object}
|
18
|
+
s.description = <<-EOF
|
19
|
+
A little (module) method to "slim down" a UTF-8 String, such as truncting consecutive CJK spaces.
|
20
|
+
EOF
|
21
|
+
# s.email = %q{abc@example.com}
|
22
|
+
s.extra_rdoc_files = [
|
23
|
+
#"LICENSE.txt",
|
24
|
+
"README.en.rdoc",
|
25
|
+
]
|
26
|
+
s.license = 'MIT'
|
27
|
+
s.files = FileList['.gitignore','lib/**/*.rb','[A-Z]*','test/**/*.rb', '*.gemspec'].to_a.delete_if{ |f|
|
28
|
+
ret = false
|
29
|
+
arignore = IO.readlines('.gitignore')
|
30
|
+
arignore.map{|i| i.chomp}.each do |suffix|
|
31
|
+
if File.fnmatch(suffix, File.basename(f))
|
32
|
+
ret = true
|
33
|
+
break
|
34
|
+
end
|
35
|
+
end
|
36
|
+
ret
|
37
|
+
}
|
38
|
+
s.files.reject! { |fn| File.symlink? fn }
|
39
|
+
|
40
|
+
# s.add_runtime_dependency 'nkf', '>= 0.1.0' # built-in so far
|
41
|
+
|
42
|
+
# s.add_development_dependency "", [">= 0.6"]
|
43
|
+
s.homepage = "https://www.wisebabel.com"
|
44
|
+
# s.rdoc_options = ["--charset=UTF-8"] # "-e UTF-8" is now Default...
|
45
|
+
|
46
|
+
# s.require_paths = ["lib"] # Default "lib"
|
47
|
+
s.required_ruby_version = '>= 2.0' # respond_to_missing?
|
48
|
+
s.test_files = Dir['test/**/*.rb']
|
49
|
+
s.test_files.reject! { |fn| File.symlink? fn }
|
50
|
+
# s.requirements << 'libmagick, v6.0' # Simply, info to users.
|
51
|
+
# s.rubygems_version = %q{1.3.5} # This is always set automatically!!
|
52
|
+
|
53
|
+
## cf. https://guides.rubygems.org/specification-reference/#metadata
|
54
|
+
s.metadata["yard.run"] = "yri" # use "yard" to build full HTML docs.
|
55
|
+
# s.metadata["changelog_uri"] = "https://github.com/masasakano/slim_string/blob/master/ChangeLog"
|
56
|
+
# s.metadata["source_code_uri"] = "https://github.com/masasakano/slim_string"
|
57
|
+
# s.metadata["documentation_uri"] = "https://www.example.info/gems/bestgemever/0.0.1"
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
# @author Masa Sakano (Wise Babel Ltd)
|
4
|
+
|
5
|
+
#require 'open3'
|
6
|
+
require 'slim_string'
|
7
|
+
|
8
|
+
$stdout.sync=true
|
9
|
+
$stderr.sync=true
|
10
|
+
# print '$LOAD_PATH=';p $LOAD_PATH
|
11
|
+
|
12
|
+
#################################################
|
13
|
+
# Unit Test
|
14
|
+
#################################################
|
15
|
+
|
16
|
+
gem "minitest"
|
17
|
+
# require 'minitest/unit'
|
18
|
+
require 'minitest/autorun'
|
19
|
+
|
20
|
+
SlimString.slim_string("a\nb\f\vc\r\n d")
|
21
|
+
|
22
|
+
include SlimString
|
23
|
+
|
24
|
+
class String
|
25
|
+
include SlimString
|
26
|
+
end
|
27
|
+
|
28
|
+
class TestSlimStringClass < MiniTest::Test
|
29
|
+
T = true
|
30
|
+
F = false
|
31
|
+
SCFNAME = File.basename(__FILE__)
|
32
|
+
# EXE = "%s/../bin/%s" % [File.dirname(__FILE__), File.basename(__FILE__).sub(/^test_(.+)\.rb/, '\1')]
|
33
|
+
|
34
|
+
def setup
|
35
|
+
end
|
36
|
+
|
37
|
+
def teardown
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_slim_string
|
41
|
+
z = "\u3000"
|
42
|
+
s = " a\nb\f\vc\r\n "+z*3+"d \r\n\r\n"
|
43
|
+
ex = " abc "+z*3+"d "
|
44
|
+
assert_equal ex, slim_string(s, delete_newlines: true, convert_blanks: false, truncate_blanks: false, strip: false, trim: false)
|
45
|
+
ex = " abc d "
|
46
|
+
assert_equal ex, slim_string(s, delete_newlines: true, truncate_blanks: false, strip: false, trim: false)
|
47
|
+
ex = " abc"+ z+ "d "
|
48
|
+
assert_equal ex, slim_string(s, delete_newlines: true, convert_blanks: false, strip: false, trim: false)
|
49
|
+
ex = "abc "+z*3+"d"
|
50
|
+
assert_equal ex, slim_string(s, delete_newlines: true, convert_blanks: false, truncate_blanks: false, trim: false)
|
51
|
+
ex = " abc "+z*3+"d"
|
52
|
+
assert_equal ex, slim_string(s, delete_newlines: true, convert_blanks: false, truncate_blanks: false, strip: false)
|
53
|
+
ex = " a\nb\f\vc\r\n "+z*3+"d"
|
54
|
+
assert_equal ex, slim_string(s, convert_blanks: false, truncate_blanks: false, strip: false)
|
55
|
+
ex = " a\nb\f\vc\r\n"+ z+ "d"
|
56
|
+
assert_equal ex, slim_string(s, convert_blanks: false, strip: false)
|
57
|
+
ex = " a\nb\f\vc\r\n d"
|
58
|
+
assert_equal ex, slim_string(s, strip: false)
|
59
|
+
ex = "a\nb\f\vc\r\n d"
|
60
|
+
assert_equal ex, slim_string(s)
|
61
|
+
ex = "a b c d"
|
62
|
+
assert_equal ex, slim_string(s, convert_spaces: true)
|
63
|
+
ex = "a\nb\vc"+ z+ "d"
|
64
|
+
assert_equal ex, slim_string(s, convert_blanks: false, truncate_spaces: true)
|
65
|
+
ex = " a\nb\f\vc\r\n "+z*3+"d \n\n"
|
66
|
+
assert_equal ex, slim_string(s, convert_blanks: false, truncate_blanks: false, truncate_triple_newlines: true, strip: false, trim: false), "inspect="+slim_string(s, convert_blanks: false, truncate_blanks: false, truncate_triple_newlines: true, strip: false, trim: false).inspect
|
67
|
+
ex = "a\nb\f\vc\r\n"+ "d"
|
68
|
+
assert_equal ex, slim_string(s, convert_blanks: false, truncate_blanks: false, delete_blanks: true, strip: false)
|
69
|
+
ex = " a\nb\f\vc\r\n "+z*3+"d \r\n\r\n"
|
70
|
+
assert_equal ex, slim_string(s, convert_blanks: false, truncate_blanks: false, strip: false, trim_blanks: true, trim: false)
|
71
|
+
|
72
|
+
assert_raises(ArgumentError){ slim_string(s, dummy: true) }
|
73
|
+
|
74
|
+
assert_equal "a\nb\f\vc\r\n d", s.slim_string()
|
75
|
+
assert_equal "a\nb\f\vc\r\n d", SlimString.slim_string(s)
|
76
|
+
end
|
77
|
+
end # class TestUnitSlimString < MiniTest::Test
|
78
|
+
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slim_string
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Masa Sakano
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ' A little (module) method to "slim down" a UTF-8 String, such as
|
14
|
+
truncting consecutive CJK spaces.
|
15
|
+
|
16
|
+
'
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files:
|
21
|
+
- README.en.rdoc
|
22
|
+
files:
|
23
|
+
- ".gitignore"
|
24
|
+
- ChangeLog
|
25
|
+
- LICENSE.txt
|
26
|
+
- Makefile
|
27
|
+
- README.en.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- lib/slim_string.rb
|
30
|
+
- slim_string.gemspec
|
31
|
+
- test/test_slim_string.rb
|
32
|
+
homepage: https://www.wisebabel.com
|
33
|
+
licenses:
|
34
|
+
- MIT
|
35
|
+
metadata:
|
36
|
+
yard.run: yri
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.1.2
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: Slim down a UTF-8 String object
|
56
|
+
test_files:
|
57
|
+
- test/test_slim_string.rb
|