From 40a3939d3abf11c21c951dfb233e71d34a8248ae Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Fri, 14 Feb 2020 15:44:21 -0700 Subject: [PATCH] Add some rubocop cleanup --- lib/strip_attributes.rb | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/strip_attributes.rb b/lib/strip_attributes.rb index f56da18..2f85a5c 100644 --- a/lib/strip_attributes.rb +++ b/lib/strip_attributes.rb @@ -19,7 +19,7 @@ def strip_attributes!(options = {}) end module StripAttributes - VALID_OPTIONS = [:only, :except, :allow_empty, :collapse_spaces, :replace_newlines, :regex, :if, :unless] + VALID_OPTIONS = [:only, :except, :allow_empty, :collapse_spaces, :replace_newlines, :regex, :if, :unless].freeze # Unicode invisible and whitespace characters. The POSIX character class # [:space:] corresponds to the Unicode class Z ("separator"). We also @@ -32,10 +32,10 @@ module StripAttributes # U+200D ZERO WIDTH JOINER # U+2060 WORD JOINER # U+FEFF ZERO WIDTH NO-BREAK SPACE - MULTIBYTE_WHITE = "\u180E\u200B\u200C\u200D\u2060\uFEFF" - MULTIBYTE_SPACE = /[[:space:]#{MULTIBYTE_WHITE}]/ - MULTIBYTE_BLANK = /[[:blank:]#{MULTIBYTE_WHITE}]/ - MULTIBYTE_SUPPORTED = "\u0020" == " " + MULTIBYTE_WHITE = "\u180E\u200B\u200C\u200D\u2060\uFEFF".freeze + MULTIBYTE_SPACE = /[[:space:]#{MULTIBYTE_WHITE}]/.freeze + MULTIBYTE_BLANK = /[[:blank:]#{MULTIBYTE_WHITE}]/.freeze + MULTIBYTE_SUPPORTED = "\u0020" == " " def self.strip(record_or_string, options = {}) if record_or_string.respond_to?(:attributes) @@ -63,13 +63,9 @@ def self.strip_string(value, options = {}) replace_newlines = options[:replace_newlines] regex = options[:regex] - if value.respond_to?(:strip) - value = value.strip - end + value = value.strip if value.respond_to?(:strip) - if regex && value.respond_to?(:gsub!) - value.gsub!(regex, "") - end + value.gsub!(regex, "") if regex && value.respond_to?(:gsub!) if MULTIBYTE_SUPPORTED && value.respond_to?(:gsub!) && Encoding.compatible?(value, MULTIBYTE_SPACE) value.gsub!(/\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/, "") @@ -77,9 +73,7 @@ def self.strip_string(value, options = {}) value.strip! end - if replace_newlines && value.respond_to?(:gsub!) - value.gsub!(/[\r\n]+/, " ") - end + value.gsub!(/[\r\n]+/, " ") if replace_newlines && value.respond_to?(:gsub!) if collapse_spaces if MULTIBYTE_SUPPORTED && value.respond_to?(:gsub!) && Encoding.compatible?(value, MULTIBYTE_BLANK)