class StringDirection::MarksStrategy

Strategy to detect direction looking for the presence of unicode marks

Constants

LTR_MARK

left-to-right unicode mark

RTL_MARK

right-to-right unicode mark

Public Instance Methods

run(string) click to toggle source

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

params [String] The string to inspect @return [String, nil]

# 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

Private Instance Methods

ltr_mark?(string) click to toggle source
# File lib/string-direction/strategies/marks_strategy.rb, line 27
def ltr_mark?(string)
  string.include?(LTR_MARK)
end
rtl_mark?(string) click to toggle source
# File lib/string-direction/strategies/marks_strategy.rb, line 31
def rtl_mark?(string)
  string.include?(RTL_MARK)
end