Class: DdbRuby::FifthEdition::Inventory
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::Inventory
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3631 def self.from_dynamic!(d) d = Types::Hash[d] new( id: d.fetch("id"), entity_type_id: d.fetch("entityTypeId"), definition: InventoryDefinition.from_dynamic!(d.fetch("definition")), definition_id: d.fetch("definitionId"), definition_type_id: d.fetch("definitionTypeId"), display_as_attack: d.fetch("displayAsAttack"), quantity: d.fetch("quantity"), is_attuned: d.fetch("isAttuned"), equipped: d.fetch("equipped"), equipped_entity_type_id: d.fetch("equippedEntityTypeId"), equipped_entity_id: d.fetch("equippedEntityId"), charges_used: d.fetch("chargesUsed"), limited_use: d.fetch("limitedUse") ? InventoryLimitedUse.from_dynamic!(d.fetch("limitedUse")) : nil, container_entity_id: d.fetch("containerEntityId"), container_entity_type_id: d.fetch("containerEntityTypeId"), container_definition_key: d.fetch("containerDefinitionKey"), currency: d.fetch("currency"), ) end |
.from_json!(json) ⇒ Object
3654 3655 3656 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3654 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3658 def to_dynamic { "id" => id, "entityTypeId" => entity_type_id, "definition" => definition.to_dynamic, "definitionId" => definition_id, "definitionTypeId" => definition_type_id, "displayAsAttack" => display_as_attack, "quantity" => quantity, "isAttuned" => is_attuned, "equipped" => equipped, "equippedEntityTypeId" => equipped_entity_type_id, "equippedEntityId" => equipped_entity_id, "chargesUsed" => charges_used, "limitedUse" => limited_use&.to_dynamic, "containerEntityId" => container_entity_id, "containerEntityTypeId" => container_entity_type_id, "containerDefinitionKey" => container_definition_key, "currency" => currency, } end |
#to_json(options = nil) ⇒ Object
3680 3681 3682 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3680 def to_json( = nil) JSON.generate(to_dynamic, ) end |