Class: DBus::Method
- Inherits:
-
InterfaceElement
- Object
- InterfaceElement
- DBus::Method
- Defined in:
- lib/dbus/introspect.rb
Overview
D-Bus interface method class
This is a class representing methods that are part of an interface.
Instance Attribute Summary collapse
-
#rets ⇒ Object
readonly
The list of return values for the method.
Attributes inherited from InterfaceElement
Instance Method Summary collapse
-
#add_return(ret) ⇒ Object
Add a return value ret.
-
#from_prototype(prototype) ⇒ Object
Add parameter types by parsing the given prototype.
-
#initialize(name) ⇒ Method
constructor
Creates a new method interface element with the given name.
-
#to_xml ⇒ Object
Return an XML string representation of the method interface elment.
Methods inherited from InterfaceElement
Constructor Details
#initialize(name) ⇒ Method
Creates a new method interface element with the given name.
117 118 119 120 |
# File 'lib/dbus/introspect.rb', line 117 def initialize(name) super(name) @rets = Array.new end |
Instance Attribute Details
#rets ⇒ Object (readonly)
The list of return values for the method.
114 115 116 |
# File 'lib/dbus/introspect.rb', line 114 def rets @rets end |
Instance Method Details
#add_return(ret) ⇒ Object
Add a return value ret.
123 124 125 |
# File 'lib/dbus/introspect.rb', line 123 def add_return(ret) @rets << ret end |
#from_prototype(prototype) ⇒ Object
Add parameter types by parsing the given prototype.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/dbus/introspect.rb', line 128 def from_prototype(prototype) prototype.split(/, */).each do |arg| arg = arg.split(" ") raise InvalidClassDefinition if arg.size != 2 dir, arg = arg if arg =~ /:/ arg = arg.split(":") name, sig = arg else sig = arg end case dir when "in" add_param([name, sig]) when "out" add_return([name, sig]) end end self end |
#to_xml ⇒ Object
Return an XML string representation of the method interface elment.
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/dbus/introspect.rb', line 150 def to_xml xml = %{<method name="#{@name}">\n} @params.each do |param| name = param[0] ? %{name="#{param[0]}" } : "" xml += %{<arg #{name}direction="in" type="#{param[1]}"/>\n} end @rets.each do |param| name = param[0] ? %{name="#{param[0]}" } : "" xml += %{<arg #{name}direction="out" type="#{param[1]}"/>\n} end xml += %{</method>\n} xml end |