Class: StringDirection::MarksStrategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/string-direction/strategies/marks_strategy.rb

Overview

Strategy to detect direction looking for the presence of unicode marks

Constant Summary collapse

LTR_MARK =

left-to-right unicode mark

"\u200e".freeze
RTL_MARK =

right-to-right unicode mark

"\u200f".freeze

Instance Method Summary collapse

Instance Method Details

#run(string) ⇒ String?

Look for the presence of unicode marks in given string and infers from them its direction

params [String] The string to inspect

Returns:

  • (String, nil)


14
15
16
17
18
19
20
21
22
23
# File 'lib/string-direction/strategies/marks_strategy.rb', line 14

def run(string)
  string = string.to_s
  if ltr_mark?(string) && rtl_mark?(string)
    bidi
  elsif ltr_mark?(string)
    ltr
  elsif rtl_mark?(string)
    rtl
  end
end