Method: StringDirection::Detector#direction

Defined in:
lib/string-direction/detector.rb

#direction(string) ⇒ String?

Tries to detect and return the direction of a string. It returns ltr if the string is left-to-right, rtl if it is right-to-left, bidi if it is bidirectional or nil if it can't detect the direction. It iterates through #strategies until one of them successes.

Parameters:

  • string (String)

    The string to inspect

Returns:

  • (String, nil)


21
22
23
24
25
26
27
28
# File 'lib/string-direction/detector.rb', line 21

def direction(string)
  direction = nil
  strategies.each do |strategy|
    direction = strategy.run(string)
    break if direction
  end
  direction
end