Class: Vangrail::Rails::Language
- Inherits:
-
Vangrail::Rail
- Object
- Vangrail::Rail
- Vangrail::Rails::Language
- Defined in:
- lib/vangrail/rails/language.rb
Overview
Reports that a page or a question is in a language nothing here can read.
Every other deterministic rail in this gem is a rule about English or Dutch words. Handed a page in German, all of them return passed, and an application reading that result cannot tell "checked and clean" from "the checks do not apply to this text". That is precisely the distinction this gem promises to keep, so the promise has to hold across languages too, and on the question as well as on the retrieved page.
So this rail never blocks. A page in an unsupported language is not an
attack, and refusing it would break a site that has one; what it is, is
unchecked, and certain? == false is the word for that. An application
reporting a safety posture can then route the page to a model rail, to a
human, or to nothing, knowing which it is doing.
Below the floor it says nothing at all. A six-word question is not evidence of a language, and marking every short turn uncertain would turn the posture into noise, which is a different way of making it useless.
Instance Attribute Summary collapse
-
#floor ⇒ Object
readonly
Returns the value of attribute floor.
-
#supported ⇒ Object
readonly
Returns the value of attribute supported.
Instance Method Summary collapse
- #cache_key(text, _context) ⇒ Object
- #call(text, _context) ⇒ Object
-
#initialize(supported: NLP::LANGUAGES, floor: NLP::LANGUAGE_FLOOR, name: 'language', sides: %i[input context])) ⇒ Language
constructor
A new instance of Language.
- #offline? ⇒ Boolean
- #posture? ⇒ Boolean
Constructor Details
#initialize(supported: NLP::LANGUAGES, floor: NLP::LANGUAGE_FLOOR, name: 'language', sides: %i[input context])) ⇒ Language
Returns a new instance of Language.
27 28 29 30 31 32 |
# File 'lib/vangrail/rails/language.rb', line 27 def initialize(supported: NLP::LANGUAGES, floor: NLP::LANGUAGE_FLOOR, name: 'language', sides: %i[input context]) super(name: name, sides: sides) @supported = Array(supported).map(&:to_sym) @floor = floor end |
Instance Attribute Details
#floor ⇒ Object (readonly)
Returns the value of attribute floor.
34 35 36 |
# File 'lib/vangrail/rails/language.rb', line 34 def floor @floor end |
#supported ⇒ Object (readonly)
Returns the value of attribute supported.
34 35 36 |
# File 'lib/vangrail/rails/language.rb', line 34 def supported @supported end |
Instance Method Details
#cache_key(text, _context) ⇒ Object
44 45 46 |
# File 'lib/vangrail/rails/language.rb', line 44 def cache_key(text, _context) "#{supported.join('+')}\n#{text}" end |
#call(text, _context) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/vangrail/rails/language.rb', line 48 def call(text, _context) reason = unread_reason(text) return unchecked(reason) if reason pass end |
#offline? ⇒ Boolean
36 37 38 |
# File 'lib/vangrail/rails/language.rb', line 36 def offline? true end |
#posture? ⇒ Boolean
40 41 42 |
# File 'lib/vangrail/rails/language.rb', line 40 def posture? true end |