Class: DBus::Type::Type
- Inherits:
-
Object
- Object
- DBus::Type::Type
- Defined in:
- lib/dbus/type.rb
Overview
D-Bus type conversion class
Helper class for representing a D-Bus type.
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Return contained member types.
-
#sigtype ⇒ Object
readonly
Returns the signature type number.
Instance Method Summary collapse
-
#<<(a) ⇒ Object
Add a new member type a.
-
#alignment ⇒ Object
Return the required alignment for the type.
-
#child ⇒ Object
Return the first contained member type.
-
#initialize(sigtype) ⇒ Type
constructor
Create a new type instance for type number sigtype.
- #inspect ⇒ Object
-
#to_s ⇒ Object
Return a string representation of the type according to the D-Bus specification.
Constructor Details
#initialize(sigtype) ⇒ Type
Create a new type instance for type number sigtype.
57 58 59 60 61 62 63 |
# File 'lib/dbus/type.rb', line 57 def initialize(sigtype) if !TypeMapping.keys.member?(sigtype) raise SignatureException, "Unknown key in signature: #{sigtype.chr}" end @sigtype = sigtype @members = [] end |
Instance Attribute Details
#members ⇒ Object (readonly)
Return contained member types.
54 55 56 |
# File 'lib/dbus/type.rb', line 54 def members @members end |
#sigtype ⇒ Object (readonly)
Returns the signature type number.
52 53 54 |
# File 'lib/dbus/type.rb', line 52 def sigtype @sigtype end |
Instance Method Details
#<<(a) ⇒ Object
Add a new member type a.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/dbus/type.rb', line 89 def <<(a) if ![STRUCT, ARRAY, DICT_ENTRY].member?(@sigtype) raise SignatureException end raise SignatureException if @sigtype == ARRAY && !@members.empty? if @sigtype == DICT_ENTRY if @members.size == 2 raise SignatureException, "Dict entries have exactly two members" end if @members.empty? if [STRUCT, ARRAY, DICT_ENTRY].member?(a.sigtype) raise SignatureException, "Dict entry keys must be basic types" end end end @members << a end |
#alignment ⇒ Object
Return the required alignment for the type.
66 67 68 |
# File 'lib/dbus/type.rb', line 66 def alignment TypeMapping[@sigtype].last end |
#child ⇒ Object
Return the first contained member type.
108 109 110 |
# File 'lib/dbus/type.rb', line 108 def child @members[0] end |
#inspect ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/dbus/type.rb', line 112 def inspect s = TypeMapping[@sigtype].first if [STRUCT, ARRAY].member?(@sigtype) s += ": " + @members.inspect end s end |
#to_s ⇒ Object
Return a string representation of the type according to the D-Bus specification.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dbus/type.rb', line 72 def to_s case @sigtype when STRUCT "(" + @members.collect(&:to_s).join + ")" when ARRAY "a" + child.to_s when DICT_ENTRY "{" + @members.collect(&:to_s).join + "}" else if !TypeMapping.keys.member?(@sigtype) raise NotImplementedError end @sigtype.chr end end |