Class: DBus::Data::Struct
Overview
A fixed size, heterogenerous tuple.
(The item count is fixed, not the byte size.)
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Container
Attributes inherited from Base
Class Method Summary collapse
- .alignment ⇒ Object
- .from_items(value, mode:, type:) ⇒ Object
- .from_typed(value, type:) ⇒ Struct
- .type_code ⇒ Object
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(value, type:) ⇒ Struct
constructor
A new instance of Struct.
Methods inherited from Container
basic?, #eql?, #exact_value, fixed?, #value
Methods inherited from Base
assert_type_matches_class, basic?, #eql?, fixed?, #type
Constructor Details
#initialize(value, type:) ⇒ Struct
Returns a new instance of Struct.
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/dbus/data.rb', line 649 def initialize(value, type:) type = Type::Factory.make_type(type) self.class.assert_type_matches_class(type) @type = type typed_value = case value when self.class unless value.type == type raise ArgumentError, "Specified type is #{type.inspect} but value type is #{value.type.inspect}" end value.exact_value else member_types = type.members unless value.size == member_types.size raise ArgumentError, "Specified type has #{member_types.size} members " \ "but value has #{value.size} members" end member_types.zip(value).map do |item_type, item| Data.make_typed(item_type, item) end end super(typed_value) end |
Class Method Details
.alignment ⇒ Object
628 629 630 |
# File 'lib/dbus/data.rb', line 628 def self.alignment 8 end |
.from_items(value, mode:, type:) ⇒ Object
633 634 635 636 637 638 |
# File 'lib/dbus/data.rb', line 633 def self.from_items(value, mode:, type:) value.freeze return value if mode == :plain new(value, type: type) end |
.from_typed(value, type:) ⇒ Struct
643 644 645 |
# File 'lib/dbus/data.rb', line 643 def self.from_typed(value, type:) new(value, type: type) end |
.type_code ⇒ Object
624 625 626 |
# File 'lib/dbus/data.rb', line 624 def self.type_code "r" end |
Instance Method Details
#==(other) ⇒ Object
676 677 678 679 680 681 682 683 684 |
# File 'lib/dbus/data.rb', line 676 def ==(other) case other when ::Struct @value.size == other.size && @value.zip(other.to_a).all? { |i, other_i| i == other_i } else super end end |