Module: Whatlang

Defined in:
lib/whatlang.rb

Defined Under Namespace

Classes: Info, Lang

Class Method Summary collapse

Class Method Details

.detect(text, allowlist: nil, denylist: nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/whatlang.rb', line 7

def detect(text, allowlist: nil, denylist: nil)
  if denylist && allowlist
    raise ArgumentError, "Couldn't specify `allowlist' and `denylist' at a time. Choose one."
  end

  text = text.to_s

  case
  when allowlist
    detect_with_allowlist(text, allowlist)
  when denylist
    detect_with_denylist(text, denylist)
  else
    detect_without_options(text)
  end
end