unicode-tools 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.ruby-version +1 -0
- data/README.md +4 -2
- data/Rakefile +1 -1
- data/lib/unicode-tools.rb +19 -7
- data/lib/unicode-tools/active_record_extension/squish.rb +24 -0
- data/lib/unicode-tools/bidi.rb +6 -6
- data/lib/unicode-tools/{string_ext → string_extension}/base.rb +4 -4
- data/lib/unicode-tools/{string_ext → string_extension}/squish.rb +4 -3
- data/lib/unicode-tools/{string_ext → string_extension}/trim.rb +7 -7
- data/lib/unicode-tools/whitespace.rb +4 -4
- data/unicode-tools.gemspec +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be6456da3acbb80d2c04ca2f095e04453d6ba5c579a27b16c87e14bc96ca7e39
|
4
|
+
data.tar.gz: fdc70c9dd6cd9de42aeb7d3c0ac5ac20d95037682c28a12fdb92680d3f40715a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90729915192ed88379196ffa0b285ab8a2ea0e1502941e64e56583d25220da6cd4c325bc9fe361395b462e21b911d721a03f5533905a9305b1e2eaf4906102e3
|
7
|
+
data.tar.gz: 8ba3de562e2249fd1478df742d31a33d75e3ecf2b8f17651700152a12b4a41021ccc1c03946ff0165a0ea8a794a346ad3a1df29304ac82d78ab62303cc424ce4
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/unicode-tools.rb
CHANGED
@@ -1,20 +1,32 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
# Override ActiveSupport's String#squish
|
4
|
+
# Override ActiveSupport's String#squish.
|
5
5
|
begin
|
6
6
|
require 'active_support/core_ext/string'
|
7
7
|
rescue LoadError
|
8
|
+
nil
|
8
9
|
end
|
9
10
|
|
10
11
|
require 'unicode-tools/whitespace'
|
11
|
-
require 'unicode-tools/
|
12
|
-
require 'unicode-tools/
|
13
|
-
require 'unicode-tools/
|
12
|
+
require 'unicode-tools/string_extension/base'
|
13
|
+
require 'unicode-tools/string_extension/trim'
|
14
|
+
require 'unicode-tools/string_extension/squish'
|
15
|
+
require 'unicode-tools/active_record_extension/squish'
|
14
16
|
require 'unicode-tools/bidi'
|
15
17
|
|
16
18
|
class String
|
17
|
-
include UnicodeTools::
|
18
|
-
include UnicodeTools::
|
19
|
-
include UnicodeTools::
|
19
|
+
include UnicodeTools::StringExtension::Base
|
20
|
+
include UnicodeTools::StringExtension::Trim
|
21
|
+
include UnicodeTools::StringExtension::Squish
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
require 'active_model'
|
26
|
+
require 'active_support/lazy_load_hooks'
|
27
|
+
|
28
|
+
ActiveModel.extend UnicodeTools::ActiveRecordExtension::Squish
|
29
|
+
ActiveSupport.on_load(:active_record) { ActiveRecord::Base.extend UnicodeTools::ActiveRecordExtension::Squish }
|
30
|
+
rescue LoadError
|
31
|
+
nil
|
20
32
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module UnicodeTools
|
5
|
+
module ActiveRecordExtension
|
6
|
+
module Squish
|
7
|
+
def squish(*attributes)
|
8
|
+
extension = Module.new
|
9
|
+
|
10
|
+
attributes.each do |attribute|
|
11
|
+
extension.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
12
|
+
def #{attribute}=(value)
|
13
|
+
super(String === value ? value.squish : value)
|
14
|
+
end
|
15
|
+
RUBY
|
16
|
+
end
|
17
|
+
|
18
|
+
include extension
|
19
|
+
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/unicode-tools/bidi.rb
CHANGED
@@ -2,19 +2,19 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module UnicodeTools
|
5
|
-
|
5
|
+
BIDI_OVERRIDE_CHARACTERS_REGEXP = /\u00E2\u0080[\u008E\u008F\u00AA-\u00AE]/.freeze
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def has_bidi_override?(string)
|
9
|
-
!!(string =~
|
9
|
+
!!(string =~ BIDI_OVERRIDE_CHARACTERS_REGEXP)
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
string.gsub(
|
12
|
+
def strip_bidi_override_characters(string)
|
13
|
+
string.gsub(BIDI_OVERRIDE_CHARACTERS_REGEXP, '')
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
string.gsub!(
|
16
|
+
def strip_bidi_override_characters!(string)
|
17
|
+
string.gsub!(BIDI_OVERRIDE_CHARACTERS_REGEXP, '')
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -2,18 +2,18 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module UnicodeTools
|
5
|
-
module
|
5
|
+
module StringExtension
|
6
6
|
module Base
|
7
7
|
def has_whitespace?
|
8
|
-
!!(self =~
|
8
|
+
!!(self =~ WHITESPACE_REGEXP)
|
9
9
|
end
|
10
10
|
|
11
11
|
def replace_whitespace(replacement = nil, &block)
|
12
|
-
gsub(
|
12
|
+
gsub(WHITESPACE_REGEXP, replacement, &block)
|
13
13
|
end
|
14
14
|
|
15
15
|
def replace_whitespace!(replacement = nil, &block)
|
16
|
-
gsub!(
|
16
|
+
gsub!(WHITESPACE_REGEXP, replacement, &block)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module UnicodeTools
|
5
|
-
module
|
5
|
+
module StringExtension
|
6
6
|
module Squish
|
7
7
|
|
8
8
|
# Removes leading, trailing whitespace and
|
@@ -18,8 +18,9 @@ module UnicodeTools
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def squish!
|
21
|
-
|
22
|
-
gsub!(
|
21
|
+
return self if empty?
|
22
|
+
gsub!(SURROUNDING_WHITESPACE_REGEXP, '')
|
23
|
+
gsub!(WHITESPACE_REGEXP, ' ')
|
23
24
|
self
|
24
25
|
end
|
25
26
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module UnicodeTools
|
5
|
-
module
|
5
|
+
module StringExtension
|
6
6
|
module Trim
|
7
7
|
|
8
8
|
# Removes leading and trailing whitespace.
|
@@ -13,27 +13,27 @@ module UnicodeTools
|
|
13
13
|
# \u2028\u2029\u202f\u205f\u3000"
|
14
14
|
# string.trim => ""
|
15
15
|
def trim
|
16
|
-
gsub(
|
16
|
+
gsub(SURROUNDING_WHITESPACE_REGEXP, '')
|
17
17
|
end
|
18
18
|
|
19
19
|
def trim!
|
20
|
-
gsub!(
|
20
|
+
gsub!(SURROUNDING_WHITESPACE_REGEXP, '')
|
21
21
|
end
|
22
22
|
|
23
23
|
def ltrim
|
24
|
-
gsub(
|
24
|
+
gsub(LEADING_WHITESPACE_REGEXP, '')
|
25
25
|
end
|
26
26
|
|
27
27
|
def ltrim!
|
28
|
-
gsub!(
|
28
|
+
gsub!(LEADING_WHITESPACE_REGEXP, '')
|
29
29
|
end
|
30
30
|
|
31
31
|
def rtrim
|
32
|
-
gsub(
|
32
|
+
gsub(TRAILING_WHITESPACE_REGEXP, '')
|
33
33
|
end
|
34
34
|
|
35
35
|
def rtrim!
|
36
|
-
gsub!(
|
36
|
+
gsub!(TRAILING_WHITESPACE_REGEXP, '')
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -7,10 +7,10 @@ module UnicodeTools
|
|
7
7
|
\u0020 \u3000 \u1680 \u2000-\u200A
|
8
8
|
\u205F \u00A0 \u202F \u180E ).freeze
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
WHITESPACE_REGEXP = /[#{WHITESPACE_CHARS.join('')}]+/.freeze
|
11
|
+
LEADING_WHITESPACE_REGEXP = /\A#{WHITESPACE_REGEXP.source}+/.freeze
|
12
|
+
TRAILING_WHITESPACE_REGEXP = /#{WHITESPACE_REGEXP.source}+\z/.freeze
|
13
|
+
SURROUNDING_WHITESPACE_REGEXP = /(\A#{WHITESPACE_REGEXP.source})|(#{WHITESPACE_REGEXP.source}\z)/.freeze
|
14
14
|
|
15
15
|
class << self
|
16
16
|
def has_whitespace?(string)
|
data/unicode-tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unicode-tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -46,15 +46,17 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
+
- ".ruby-version"
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE.txt
|
51
52
|
- README.md
|
52
53
|
- Rakefile
|
53
54
|
- lib/unicode-tools.rb
|
55
|
+
- lib/unicode-tools/active_record_extension/squish.rb
|
54
56
|
- lib/unicode-tools/bidi.rb
|
55
|
-
- lib/unicode-tools/
|
56
|
-
- lib/unicode-tools/
|
57
|
-
- lib/unicode-tools/
|
57
|
+
- lib/unicode-tools/string_extension/base.rb
|
58
|
+
- lib/unicode-tools/string_extension/squish.rb
|
59
|
+
- lib/unicode-tools/string_extension/trim.rb
|
58
60
|
- lib/unicode-tools/whitespace.rb
|
59
61
|
- test/test_unicode_tools.rb
|
60
62
|
- unicode-tools.gemspec
|
@@ -77,8 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
79
|
- !ruby/object:Gem::Version
|
78
80
|
version: '0'
|
79
81
|
requirements: []
|
80
|
-
|
81
|
-
rubygems_version: 2.5.1
|
82
|
+
rubygems_version: 3.1.2
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: Unicode-friendly String#trim and String#squish
|