Class: DBus::Data::Boolean
Overview
Boolean: encoded as a UInt32 but only 0 and 1 are valid.
Constant Summary collapse
- FORMAT =
Format.new("L<", "L>")
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
- .alignment ⇒ Object
- .format ⇒ Object
- .from_raw(value, mode:) ⇒ Object
- .type_code ⇒ Object
- .validate_raw!(value) ⇒ Object
Instance Method Summary collapse
-
#initialize(value) ⇒ Boolean
constructor
Accept any value, store its Ruby truth value (excepting another instance of this class, where use its DBus::Data::Base#value).
- #marshall(endianness) ⇒ Object
Methods inherited from Fixed
Methods inherited from Basic
basic?, from_typed, type, #type
Methods inherited from Base
#==, assert_type_matches_class, basic?, #eql?, fixed?, from_typed, #type
Constructor Details
#initialize(value) ⇒ Boolean
Accept any value, store its Ruby truth value (excepting another instance of this class, where use its DBus::Data::Base#value).
So new(0).value is true.
235 236 237 238 |
# File 'lib/dbus/data.rb', line 235 def initialize(value) value = value.value if value.is_a?(self.class) super(value ? true : false) end |
Class Method Details
.alignment ⇒ Object
207 208 209 |
# File 'lib/dbus/data.rb', line 207 def self.alignment 4 end |
.from_raw(value, mode:) ⇒ Object
221 222 223 224 225 226 227 228 |
# File 'lib/dbus/data.rb', line 221 def self.from_raw(value, mode:) validate_raw!(value) value = value == 1 return value if mode == :plain new(value) end |
.type_code ⇒ Object
203 204 205 |
# File 'lib/dbus/data.rb', line 203 def self.type_code "b" end |
.validate_raw!(value) ⇒ Object
215 216 217 218 219 |
# File 'lib/dbus/data.rb', line 215 def self.validate_raw!(value) return if [0, 1].member?(value) raise InvalidPacketException, "BOOLEAN must be 0 or 1, found #{value}" end |