Class: Translate::Detection

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#keyObject (readonly)

Returns the value of attribute key.



34
35
36
# File 'lib/rtranslate/detection.rb', line 34

def key
  @key
end

#versionObject (readonly)

Returns the value of attribute version.



34
35
36
# File 'lib/rtranslate/detection.rb', line 34

def version
  @version
end

Class Method Details

.dObject



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

def detect(text)
  Detection.new.detect(text)
end

.detect(text) ⇒ Object



37
38
39
# File 'lib/rtranslate/detection.rb', line 37

def detect(text)
  Detection.new.detect(text)
end

Instance Method Details

#detect(text, 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=#{text}&v=#{@version}"
  if @key
    url << "&key=#{@key}"
  end
  detection_response = do_detect(url)
  details ? detection_response : detection_response.abbrev
end