Class: Nabaztag::Response

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/nabaztag/response.rb

Constant Summary collapse

ERROR_MESSAGES =
/^NO|^ABUSE|NOTSENT$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Response

Returns a new instance of Response.



11
12
13
14
# File 'lib/nabaztag/response.rb', line 11

def initialize(xml)
  @raw = xml
  @doc = Document.new(xml)
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'lib/nabaztag/response.rb', line 9

def raw
  @raw
end

Instance Method Details

#commentsObject



20
21
22
# File 'lib/nabaztag/response.rb', line 20

def comments
  lookup('/rsp/comment')
end

#friendsObject



24
25
26
# File 'lib/nabaztag/response.rb', line 24

def friends
  lookup('/rsp/friend@name')
end

#languagesObject



49
50
51
# File 'lib/nabaztag/response.rb', line 49

def languages
  lookup('/rsp/myLang@lang')
end

#left_earObject



53
54
55
56
# File 'lib/nabaztag/response.rb', line 53

def left_ear
  position = lookup('/rsp/leftposition').first
  position && position.to_i
end

#messagesObject



16
17
18
# File 'lib/nabaztag/response.rb', line 16

def messages
  lookup('/rsp/message')
end

#rabbit_nameObject



36
37
38
# File 'lib/nabaztag/response.rb', line 36

def rabbit_name
  lookup('/rsp/rabbitName').first
end

#rabbit_versionObject



32
33
34
# File 'lib/nabaztag/response.rb', line 32

def rabbit_version
  lookup('/rsp/rabbitVersion').first
end

#right_earObject



58
59
60
61
# File 'lib/nabaztag/response.rb', line 58

def right_ear
  position = lookup('/rsp/rightposition').first
  position && position.to_i
end

#signatureObject



63
64
65
# File 'lib/nabaztag/response.rb', line 63

def signature
  lookup('/rsp/signature')
end

#success?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/nabaztag/response.rb', line 67

def success?
  !messages.any?{ |m| m =~ ERROR_MESSAGES }
end

#timezoneObject



28
29
30
# File 'lib/nabaztag/response.rb', line 28

def timezone
  lookup('/rsp/timezone').first
end

#voicesObject



40
41
42
43
44
45
46
47
# File 'lib/nabaztag/response.rb', line 40

def voices
  XPath.match(@doc, '/rsp/voice').inject({}){ |h, n|
    lang    = n.attributes['lang']
    command = n.attributes['command']
    (h[lang] ||= []) << command
    h
  }
end