diaspora/lib/direction_detector.rb
2016-11-15 22:33:56 +01:00

25 lines
629 B
Ruby

# coding: utf-8
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class String
RTL_CLEANER_REGEXES = [ /@[^ ]+|#[^ ]+/u, # mention, tag
/^RT[: ]{1}| RT | RT: |[♺♻:]/u # retweet
]
def is_rtl?
return false if self.strip.empty?
detector = StringDirection::Detector.new(:dominant)
detector.rtl? self
end
# Diaspora specific
def cleaned_is_rtl?
string = String.new(self)
RTL_CLEANER_REGEXES.each do |cleaner|
string.gsub!(cleaner, '')
end
string.is_rtl?
end
end