Class: Nabaztag::Response
- Inherits:
-
Object
- Object
- Nabaztag::Response
- Includes:
- REXML
- Defined in:
- lib/nabaztag/response.rb
Constant Summary collapse
- ERROR_MESSAGES =
/^NO|^ABUSE|NOTSENT$/
Instance Attribute Summary collapse
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
- #comments ⇒ Object
- #friends ⇒ Object
-
#initialize(xml) ⇒ Response
constructor
A new instance of Response.
- #languages ⇒ Object
- #left_ear ⇒ Object
- #messages ⇒ Object
- #rabbit_name ⇒ Object
- #rabbit_version ⇒ Object
- #right_ear ⇒ Object
- #signature ⇒ Object
- #success? ⇒ Boolean
- #timezone ⇒ Object
- #voices ⇒ Object
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
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
9 10 11 |
# File 'lib/nabaztag/response.rb', line 9 def raw @raw end |
Instance Method Details
#comments ⇒ Object
20 21 22 |
# File 'lib/nabaztag/response.rb', line 20 def comments lookup('/rsp/comment') end |
#friends ⇒ Object
24 25 26 |
# File 'lib/nabaztag/response.rb', line 24 def friends lookup('/rsp/friend@name') end |
#languages ⇒ Object
49 50 51 |
# File 'lib/nabaztag/response.rb', line 49 def languages lookup('/rsp/myLang@lang') end |
#left_ear ⇒ Object
53 54 55 56 |
# File 'lib/nabaztag/response.rb', line 53 def left_ear position = lookup('/rsp/leftposition').first position && position.to_i end |
#messages ⇒ Object
16 17 18 |
# File 'lib/nabaztag/response.rb', line 16 def lookup('/rsp/message') end |
#rabbit_name ⇒ Object
36 37 38 |
# File 'lib/nabaztag/response.rb', line 36 def rabbit_name lookup('/rsp/rabbitName').first end |
#rabbit_version ⇒ Object
32 33 34 |
# File 'lib/nabaztag/response.rb', line 32 def rabbit_version lookup('/rsp/rabbitVersion').first end |
#right_ear ⇒ Object
58 59 60 61 |
# File 'lib/nabaztag/response.rb', line 58 def right_ear position = lookup('/rsp/rightposition').first position && position.to_i end |
#signature ⇒ Object
63 64 65 |
# File 'lib/nabaztag/response.rb', line 63 def signature lookup('/rsp/signature') end |
#success? ⇒ Boolean
67 68 69 |
# File 'lib/nabaztag/response.rb', line 67 def success? !.any?{ |m| m =~ ERROR_MESSAGES } end |
#timezone ⇒ Object
28 29 30 |
# File 'lib/nabaztag/response.rb', line 28 def timezone lookup('/rsp/timezone').first end |
#voices ⇒ Object
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 |