Class: LangDect

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text_to_detect) ⇒ LangDect

Returns a new instance of LangDect.



12
13
14
15
16
17
# File 'lib/langdect.rb', line 12

def initialize(text_to_detect)
  @error = false
  @lang = nil
  @text = text_to_detect[0..200]
  detect
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#langObject (readonly)

Returns the value of attribute lang.



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

def lang
  @lang
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#detectObject



18
19
20
21
22
23
# File 'lib/langdect.rb', line 18

def detect
  Curl::Easy.http_get('http://www.google.com/uds/GlangDetect?v=1.0&q=' + CGI.escape(@text)) do |request|
    request.on_failure { @error = true }
    request.on_success { @lang = JSON.load(request.body_str)['responseData'] }
  end
end