Class: UnicodeScriptDetector::SpoofDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/unicode_script_detector/spoof_detector.rb

Defined Under Namespace

Classes: ConfusableChar, Detection, InvisibleChar

Constant Summary collapse

SEVERITY_HIGH =
:high
SEVERITY_MEDIUM =
:medium
SEVERITY_LOW =
:low

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ SpoofDetector

Returns a new instance of SpoofDetector.



11
12
13
14
# File 'lib/unicode_script_detector/spoof_detector.rb', line 11

def initialize(string)
  @string = string.to_s
  @detections = nil
end

Instance Method Details

#confusablesObject

Returns only confusable character detections



32
33
34
# File 'lib/unicode_script_detector/spoof_detector.rb', line 32

def confusables
  detections.select { |d| d.type == :confusable }
end

#detectionsObject

Returns all spoof detections found in the string



17
18
19
20
21
22
23
24
# File 'lib/unicode_script_detector/spoof_detector.rb', line 17

def detections
  @detections ||= [
    detect_confusables,
    detect_invisible_characters,
    detect_directional_overrides,
    detect_mixed_scripts
  ].compact
end

#invisible_charactersObject

Returns only invisible character detections



37
38
39
# File 'lib/unicode_script_detector/spoof_detector.rb', line 37

def invisible_characters
  detections.select { |d| d.type == :invisible }
end

#mixed_scriptsObject

Returns only mixed script detections



42
43
44
# File 'lib/unicode_script_detector/spoof_detector.rb', line 42

def mixed_scripts
  detections.select { |d| d.type == :mixed_scripts }
end

#spoofed?Boolean

Returns true if any spoofing is detected

Returns:

  • (Boolean)


27
28
29
# File 'lib/unicode_script_detector/spoof_detector.rb', line 27

def spoofed?
  detections.any?
end