Class: Rmpd::Response
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Rmpd::Response
show all
- Defined in:
- lib/rmpd/response.rb
Constant Summary
collapse
- KEY_VALUE_RE =
/^([^:]+):\s*(.*)$/
- KNOWN_INT_FIELDS =
[
"bitrate",
"consume",
"id",
"nextsong",
"nextsongid",
"playlist",
"playlistlength",
"playtime",
"pos",
"queued",
"random",
"repeat",
"single",
"song",
"songid",
"songs",
"track",
"volume",
"xfade",
]
- KNOWN_FLOAT_FIELDS =
[
"elapsed",
"mixrampdb",
]
- KNOWN_COMPLEX_FIELDS =
[
"time",
"audio"
]
- MULTI_RESPONSE_COMMANDS =
[
"commands",
"find",
"idle",
"list",
"outputs",
"playlistinfo",
"plchanges",
"plchangesposid",
"search",
"tagtypes",
]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parent) ⇒ Response
Returns a new instance of Response.
69
70
71
72
|
# File 'lib/rmpd/response.rb', line 69
def initialize(parent)
super
@error = nil
end
|
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
50
51
52
|
# File 'lib/rmpd/response.rb', line 50
def error
@error
end
|
Class Method Details
.choose_strategy(name) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/rmpd/response.rb', line 53
def self.choose_strategy(name)
if MULTI_RESPONSE_COMMANDS.include?(name.to_s)
[Array, ResponseMultiStrategy]
else
[Hash, ResponseSingleStrategy]
end
end
|
.factory(command_name) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/rmpd/response.rb', line 61
def self.factory(command_name)
if MULTI_RESPONSE_COMMANDS.include?(command_name.to_s)
MultiResponse.new
else
SingleResponse.new
end
end
|
Instance Method Details
#ack? ⇒ Boolean
87
88
89
|
# File 'lib/rmpd/response.rb', line 87
def ack?
!ok?
end
|
#marshal_dump ⇒ Object
74
75
76
|
# File 'lib/rmpd/response.rb', line 74
def marshal_dump
[@delegate_sd_obj, @error]
end
|
#marshal_load(array) ⇒ Object
78
79
80
81
|
# File 'lib/rmpd/response.rb', line 78
def marshal_load(array)
@delegate_sd_obj, @error = array
each {|k, v| define_getter(k)}
end
|
#ok? ⇒ Boolean
83
84
85
|
# File 'lib/rmpd/response.rb', line 83
def ok?
@error.nil?
end
|
#parse(lines) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/rmpd/response.rb', line 91
def parse(lines)
lines.each do |line|
case line
when KEY_VALUE_RE
register_key_val_pair($~)
when ACK_RE
@error = $~[0]
break
when OK_RE
break
else
$stderr.puts "Don't know how to parse: #{line}"
end
end
self
end
|