Class: Translate::Detection
- Inherits:
-
Object
- Object
- Translate::Detection
- Defined in:
- lib/rtranslate/detection.rb
Constant Summary collapse
- GOOGLE_DETECTION_URL =
Google AJAX Language REST Service URL
"http://ajax.googleapis.com/ajax/services/language/detect"
- DEFAULT_VERSION =
Default version of Google AJAX Language API
"1.0"
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #detect(text, options = {:details => false}) ⇒ Object
-
#initialize(version = DEFAULT_VERSION, key = nil) ⇒ Detection
constructor
A new instance of Detection.
Constructor Details
#initialize(version = DEFAULT_VERSION, key = nil) ⇒ Detection
Returns a new instance of Detection.
43 44 45 46 |
# File 'lib/rtranslate/detection.rb', line 43 def initialize(version = DEFAULT_VERSION, key = nil) @version = version @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
34 35 36 |
# File 'lib/rtranslate/detection.rb', line 34 def key @key end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
34 35 36 |
# File 'lib/rtranslate/detection.rb', line 34 def version @version end |
Class Method Details
Instance Method Details
#detect(text, options = {:details => false}) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/rtranslate/detection.rb', line 48 def detect(text, = {:details => false}) url = "#{GOOGLE_DETECTION_URL}?q=#{CGI.escape(text)}&v=#{@version}" url << "&key=#{@key}" if @key url << "&userip=#{[:userip]}" if [:userip] detection_response = do_detect(url) [:details] ? detection_response : detection_response.abbrev end |