Module: DetectLanguage

Defined in:
lib/detect_language.rb,
lib/detect_language/client.rb,
lib/detect_language/errors.rb,
lib/detect_language/version.rb,
lib/detect_language/configuration.rb

Defined Under Namespace

Classes: Client, Configuration, Error, Exception

Constant Summary collapse

VERSION =
"1.0.6"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

The configuration object.

See Also:



16
17
18
# File 'lib/detect_language.rb', line 16

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.clientObject



20
21
22
# File 'lib/detect_language.rb', line 20

def client
  @client ||= Client.new(configuration)
end

.configure {|configuration| ... } ⇒ Object

Yields:



10
11
12
# File 'lib/detect_language.rb', line 10

def configure
  yield(configuration)
end

.detect(data) ⇒ Object



24
25
26
27
28
# File 'lib/detect_language.rb', line 24

def detect(data)
  key = data.is_a?(Array) ? 'q[]' : 'q'
  result = client.post(:detect, key => data)
  result['data']['detections']
end

.languagesObject



44
45
46
# File 'lib/detect_language.rb', line 44

def languages
  client.get('languages')
end

.simple_detect(text) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/detect_language.rb', line 30

def simple_detect(text)
  detections = detect(text)

  if detections.empty?
    nil
  else
    detections[0]['language']
  end
end

.user_statusObject



40
41
42
# File 'lib/detect_language.rb', line 40

def user_status
  client.post('user/status')
end