Class: Cogger::Formatters::Sanitizers::Escape
- Inherits:
-
Object
- Object
- Cogger::Formatters::Sanitizers::Escape
- Defined in:
- lib/cogger/formatters/sanitizers/escape.rb
Overview
Sanitizes value as fully quoted string for emojis, spaces, and control characters.
Constant Summary collapse
- PATTERN =
/ \A # Search string start. .* # Match zero or more characters. ( # Conditional start. (?!\p{Number}) # Look ahead and ignore unicode numbers. \p{Emoji} # Match unicode emoji only. | # Or. [[:space:]] # Match spaces, tabs, and new lines. | # Or. [[:cntrl:]] # Match control characters. ) # Conditional end. .* # Match zero or more characters. \z # Search string end. /xu
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(pattern: PATTERN) ⇒ Escape
constructor
A new instance of Escape.
Constructor Details
Instance Method Details
#call(value) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/cogger/formatters/sanitizers/escape.rb', line 27 def call value return dump value unless value.is_a? Array value.reduce(+"") { |text, item| text << dump(item) << ", " } .then { |text| %([#{text.delete_suffix ", "}]).dump } end |