class Roqua::Type::StrippedString
Constants
- MULTIBYTE_SPACE
- MULTIBYTE_WHITE
taken from strip_attributes gem Unicode invisible and whitespace characters. The POSIX character class
- :space:
-
corresponds to the Unicode class Z (“separator”). We also
include the following characters from Unicode class C (“control”), which are spaces or invisible characters that make no sense at the start or end of a string:
U+180E MONGOLIAN VOWEL SEPARATOR U+200B ZERO WIDTH SPACE U+200C ZERO WIDTH NON-JOINER U+200D ZERO WIDTH JOINER U+2060 WORD JOINER U+FEFF ZERO WIDTH NO-BREAK SPACE
Public Class Methods
new(allow_empty: false)
click to toggle source
Calls superclass method
# File lib/roqua/type/stripped_string.rb, line 22 def initialize(allow_empty: false) super() @allow_empty = allow_empty end
Public Instance Methods
cast(value)
click to toggle source
Calls superclass method
# File lib/roqua/type/stripped_string.rb, line 27 def cast(value) return unless value value = super(value).gsub(/\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/, "").freeze value.blank? && !@allow_empty ? nil : value end