Welcome to mirror list, hosted at ThFree Co, Russian Federation.

direction_detector.rb « lib - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7ed020cbdd704dc185d47be25279a1380f90e63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# coding: utf-8
# frozen_string_literal: true

#   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