Class: WtfLang::API
- Inherits:
-
Object
- Object
- WtfLang::API
- Defined in:
- lib/wtf_lang/api.rb
Constant Summary collapse
- BASE_URL =
"http://www.google.com/uds/GlangDetect"
- VERSION =
"?v=1.0"
Class Method Summary collapse
- .detect(text) ⇒ Object
- .get_url(text) ⇒ Object
- .lang(text) ⇒ Object
-
.lang_confidence(text) ⇒ Object
A numeric value between 0-1.0 that represents the confidence level in the language code for the given text.
- .parse(response) ⇒ Object
- .send(text) ⇒ Object
Class Method Details
.detect(text) ⇒ Object
26 27 28 29 |
# File 'lib/wtf_lang/api.rb', line 26 def detect(text) response = send(text) parse(response) end |
.get_url(text) ⇒ Object
14 15 16 |
# File 'lib/wtf_lang/api.rb', line 14 def get_url(text) BASE_URL+VERSION+"&q="+CGI.escape(text) end |
.lang(text) ⇒ Object
31 32 33 |
# File 'lib/wtf_lang/api.rb', line 31 def lang(text) detect(text)["responseData"]["language"] end |
.lang_confidence(text) ⇒ Object
A numeric value between 0-1.0 that represents the confidence level in the language code for the given text.
36 37 38 |
# File 'lib/wtf_lang/api.rb', line 36 def lang_confidence(text) [detect(text)["responseData"]["language"], detect(text)["responseData"]["confidence"]] end |
.parse(response) ⇒ Object
22 23 24 |
# File 'lib/wtf_lang/api.rb', line 22 def parse(response) JSON.parse(response) end |
.send(text) ⇒ Object
18 19 20 |
# File 'lib/wtf_lang/api.rb', line 18 def send(text) Net::HTTP.get(URI.parse(get_url(text))) end |