Class: StringDirection::CharactersStrategy
- Defined in:
- lib/string-direction/strategies/characters_strategy.rb
Overview
Strategy to detect direction from the scripts to which string characters belong
Direct Known Subclasses
Constant Summary collapse
- IGNORED_CHARS =
Ignored characters: unicode marks, punctuations, symbols, separator and other general categories
'\p{M}\p{P}\p{S}\p{Z}\p{C}'.freeze
Instance Method Summary collapse
-
#run(string) ⇒ String?
Inspect to wich scripts characters belongs and infer from them the string direction.
Instance Method Details
#run(string) ⇒ String?
Inspect to wich scripts characters belongs and infer from them the string direction. right-to-left scripts are those in StringDirection::Configuration#rtl_scripts
params [String] The string to inspect
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/string-direction/strategies/characters_strategy.rb', line 11 def run(string) string = string.to_s if ltr_characters?(string) && rtl_characters?(string) bidi elsif ltr_characters?(string) ltr elsif rtl_characters?(string) rtl end end |