Class: LangDect
- Inherits:
-
Object
- Object
- LangDect
- Defined in:
- lib/langdect.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#lang ⇒ Object
readonly
Returns the value of attribute lang.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
- #detect ⇒ Object
-
#initialize(text_to_detect) ⇒ LangDect
constructor
A new instance of LangDect.
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
#error ⇒ Object (readonly)
Returns the value of attribute error.
10 11 12 |
# File 'lib/langdect.rb', line 10 def error @error end |
#lang ⇒ Object (readonly)
Returns the value of attribute lang.
10 11 12 |
# File 'lib/langdect.rb', line 10 def lang @lang end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
10 11 12 |
# File 'lib/langdect.rb', line 10 def text @text end |
Instance Method Details
#detect ⇒ Object
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 |