Module: YandexDetector::Properties

Included in:
Result
Defined in:
lib/yandex_detector/result/properties.rb

Overview

This module contain YandexDetector::Result instance’s methods, which allow to determine concrete properties of result

Instance Method Summary collapse

Instance Method Details

#android?Bool

Returns android detected.

Returns:

  • (Bool)

    android detected



38
39
40
# File 'lib/yandex_detector/result/properties.rb', line 38

def android?
  device_class === 'android'
end

#blackberry?Bool

Returns blackberry detected.

Returns:

  • (Bool)

    blackberry detected



43
44
45
# File 'lib/yandex_detector/result/properties.rb', line 43

def blackberry?
  device_class === 'rim'
end

#dataHash

Returns Hash representation of API service’s answer according to documentation http://api.yandex.ru/detector/doc/dg/concepts/detector-response.xml. All ‘-’ signs in tag names replaced by ‘_’ and tag names converted to symbols to use as Hash’s keys.

Returns:



59
60
61
62
63
64
65
# File 'lib/yandex_detector/result/properties.rb', line 59

def data
  begin
    @data[:data]
  rescue
    nil
  end
end

#device_classString?

Returns device_class string according to documentation http://api.yandex.ru/detector/doc/dg/concepts/detector-response.xml.

Returns:



49
50
51
52
53
54
55
# File 'lib/yandex_detector/result/properties.rb', line 49

def device_class
  begin
    @data[:data][:yandex_mobile_info][:device_class]
  rescue
    nil
  end
end

#error?Bool

Returns any error occured.

Returns:

  • (Bool)

    any error occured



13
14
15
# File 'lib/yandex_detector/result/properties.rb', line 13

def error?
  !request_performed? or @data.nil? or !@data[:error].nil?
end

#error_messageString?

Returns error message if present, or nil otherwise.

Returns:

  • (String, nil)

    error message if present, or nil otherwise



18
19
20
21
22
23
24
# File 'lib/yandex_detector/result/properties.rb', line 18

def error_message
  begin
    @data[:error]
  rescue
    nil
  end
end

#iphone?Bool

Returns iphone detected.

Returns:

  • (Bool)

    iphone detected



33
34
35
# File 'lib/yandex_detector/result/properties.rb', line 33

def iphone?
  device_class === 'iphoneos'
end

#request_performed?Bool

Returns network request to API service was performed.

Returns:

  • (Bool)

    network request to API service was performed



7
8
9
# File 'lib/yandex_detector/result/properties.rb', line 7

def request_performed?
  @request_performed
end

#success?Bool

Returns no error occured.

Returns:

  • (Bool)

    no error occured



27
28
29
# File 'lib/yandex_detector/result/properties.rb', line 27

def success?
  !error?
end

#textString

Returns Text representation of API service’s answer according to documentation http://api.yandex.ru/detector/doc/dg/concepts/detector-response.xml.

Returns:



68
69
70
71
72
73
74
# File 'lib/yandex_detector/result/properties.rb', line 68

def text
  begin
    @data[:text]
  rescue
    nil
  end      
end