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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6834d7b0f651c4840d229d3d5ade2cb83259ac9e
4
- data.tar.gz: 2d077366c430ad94ce494f6e4b7d1be976090de4
2
+ SHA256:
3
+ metadata.gz: be6456da3acbb80d2c04ca2f095e04453d6ba5c579a27b16c87e14bc96ca7e39
4
+ data.tar.gz: fdc70c9dd6cd9de42aeb7d3c0ac5ac20d95037682c28a12fdb92680d3f40715a
5
5
  SHA512:
6
- metadata.gz: 9b22e9e651d0aadc5e6c29fcce3eff1d6f62b0eadf41b64756615ea46fb1c80e31f92e2a94b09f9149d8b597e3a79cdf3ed7b5ec73cae61900523c153f2b6b82
7
- data.tar.gz: 39a1d66a3a27b5f34b9b9b61c09f37efe27b7e005b63dfd1037910ab20410a44a9460c2efcb96d15f6e68adefb726d8b4817bdb770315d2cfbc2a851535c63d9
6
+ metadata.gz: 90729915192ed88379196ffa0b285ab8a2ea0e1502941e64e56583d25220da6cd4c325bc9fe361395b462e21b911d721a03f5533905a9305b1e2eaf4906102e3
7
+ data.tar.gz: 8ba3de562e2249fd1478df742d31a33d75e3ecf2b8f17651700152a12b4a41021ccc1c03946ff0165a0ea8a794a346ad3a1df29304ac82d78ab62303cc424ce4
@@ -0,0 +1 @@
1
+ 2.7.1
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
- ## Unicode-friendly String#trim and String#squish
1
+ # Unicode-friendly String#trim and String#squish
2
+
2
3
  ## Gemfile
4
+
3
5
  ```ruby
4
- gem 'unicode-tools', '~> 1.0'
6
+ gem 'unicode-tools', '~> 2.0.0'
5
7
  ```
data/Rakefile CHANGED
@@ -7,4 +7,4 @@ require 'bundler/gem_tasks'
7
7
  Rake::TestTask.new { |t| t.libs << 'test' }
8
8
 
9
9
  desc 'Run test suite'
10
- task :default => :test
10
+ task default: :test
@@ -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/string_ext/base'
12
- require 'unicode-tools/string_ext/trim'
13
- require 'unicode-tools/string_ext/squish'
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::StringExt::Base
18
- include UnicodeTools::StringExt::Trim
19
- include UnicodeTools::StringExt::Squish
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
@@ -2,19 +2,19 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module UnicodeTools
5
- BIDI_OVERRIDE_CHARS_REGEX = /\u00E2\u0080[\u008E\u008F\u00AA-\u00AE]/.freeze
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 =~ BIDI_OVERRIDE_CHARS_REGEX)
9
+ !!(string =~ BIDI_OVERRIDE_CHARACTERS_REGEXP)
10
10
  end
11
11
 
12
- def strip_bidi_override_chars(string)
13
- string.gsub(BIDI_OVERRIDE_CHARS_REGEX, '')
12
+ def strip_bidi_override_characters(string)
13
+ string.gsub(BIDI_OVERRIDE_CHARACTERS_REGEXP, '')
14
14
  end
15
15
 
16
- def strip_bidi_override_chars!(string)
17
- string.gsub!(BIDI_OVERRIDE_CHARS_REGEX, '')
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 StringExt
5
+ module StringExtension
6
6
  module Base
7
7
  def has_whitespace?
8
- !!(self =~ WHITESPACE_REGEX)
8
+ !!(self =~ WHITESPACE_REGEXP)
9
9
  end
10
10
 
11
11
  def replace_whitespace(replacement = nil, &block)
12
- gsub(WHITESPACE_REGEX, replacement, &block)
12
+ gsub(WHITESPACE_REGEXP, replacement, &block)
13
13
  end
14
14
 
15
15
  def replace_whitespace!(replacement = nil, &block)
16
- gsub!(WHITESPACE_REGEX, replacement, &block)
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 StringExt
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
- gsub!(SURROUNDING_WHITESPACE_REGEX, '')
22
- gsub!(WHITESPACE_REGEX, ' ')
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 StringExt
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(SURROUNDING_WHITESPACE_REGEX, '')
16
+ gsub(SURROUNDING_WHITESPACE_REGEXP, '')
17
17
  end
18
18
 
19
19
  def trim!
20
- gsub!(SURROUNDING_WHITESPACE_REGEX, '')
20
+ gsub!(SURROUNDING_WHITESPACE_REGEXP, '')
21
21
  end
22
22
 
23
23
  def ltrim
24
- gsub(LEADING_WHITESPACE_REGEX, '')
24
+ gsub(LEADING_WHITESPACE_REGEXP, '')
25
25
  end
26
26
 
27
27
  def ltrim!
28
- gsub!(LEADING_WHITESPACE_REGEX, '')
28
+ gsub!(LEADING_WHITESPACE_REGEXP, '')
29
29
  end
30
30
 
31
31
  def rtrim
32
- gsub(TRAILING_WHITESPACE_REGEX, '')
32
+ gsub(TRAILING_WHITESPACE_REGEXP, '')
33
33
  end
34
34
 
35
35
  def rtrim!
36
- gsub!(TRAILING_WHITESPACE_REGEX, '')
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
- WHITESPACE_REGEX = /[#{WHITESPACE_CHARS.join('')}]+/.freeze
11
- LEADING_WHITESPACE_REGEX = /\A#{WHITESPACE_REGEX.source}+/.freeze
12
- TRAILING_WHITESPACE_REGEX = /#{WHITESPACE_REGEX.source}+\z/.freeze
13
- SURROUNDING_WHITESPACE_REGEX = /(\A#{WHITESPACE_REGEX.source})|(#{WHITESPACE_REGEX.source}\z)/.freeze
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)
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'unicode-tools'
6
- s.version = '1.0.2'
6
+ s.version = '2.0.0'
7
7
  s.authors = ['Yaroslav Konoplov']
8
8
  s.email = ['eahome00@gmail.com']
9
9
  s.summary = 'Unicode-friendly String#trim and String#squish'
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: 1.0.2
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: 2016-10-20 00:00:00.000000000 Z
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/string_ext/base.rb
56
- - lib/unicode-tools/string_ext/squish.rb
57
- - lib/unicode-tools/string_ext/trim.rb
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
- rubyforge_project:
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