Class: DdbRuby::FifthEdition::InventoryDefinition
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::InventoryDefinition
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3448 def self.from_dynamic!(d) d = Types::Hash[d] new( id: d.fetch("id"), base_type_id: d.fetch("baseTypeId"), entity_type_id: d.fetch("entityTypeId"), definition_key: d.fetch("definitionKey"), can_equip: d.fetch("canEquip"), magic: d.fetch("magic"), definition_name: d.fetch("name"), snippet: d.fetch("snippet"), weight: d.fetch("weight"), weight_multiplier: d.fetch("weightMultiplier"), capacity: d.fetch("capacity"), capacity_weight: d.fetch("capacityWeight"), definition_type: d.fetch("type"), description: d.fetch("description"), can_attune: d.fetch("canAttune"), attunement_description: d.fetch("attunementDescription"), rarity: d.fetch("rarity"), is_homebrew: d.fetch("isHomebrew"), version: d.fetch("version"), source_id: d.fetch("sourceId"), source_page_number: d.fetch("sourcePageNumber"), stackable: d.fetch("stackable"), bundle_size: d.fetch("bundleSize"), avatar_url: d.fetch("avatarUrl"), large_avatar_url: d.fetch("largeAvatarUrl"), filter_type: d.fetch("filterType"), cost: d.fetch("cost"), is_pack: d.fetch("isPack"), tags: d.fetch("tags"), granted_modifiers: d.fetch("grantedModifiers").map { |x| ItemElement.from_dynamic!(x) }, sub_type: d.fetch("subType"), is_consumable: d.fetch("isConsumable"), weapon_behaviors: d.fetch("weaponBehaviors").map { |x| WeaponBehavior.from_dynamic!(x) }, base_item_id: d.fetch("baseItemId"), base_armor_name: d.fetch("baseArmorName"), strength_requirement: d.fetch("strengthRequirement"), armor_class: d.fetch("armorClass"), stealth_check: d.fetch("stealthCheck"), damage: d.fetch("damage") ? HitPointDice.from_dynamic!(d.fetch("damage")) : nil, damage_type: d.fetch("damageType"), fixed_damage: d.fetch("fixedDamage"), properties: d.fetch("properties")&.map { |x| Organization.from_dynamic!(x) }, attack_type: d.fetch("attackType"), category_id: d.fetch("categoryId"), range: d.fetch("range"), long_range: d.fetch("longRange"), is_monk_weapon: d.fetch("isMonkWeapon"), level_infusion_granted: d.fetch("levelInfusionGranted"), sources: d.fetch("sources").map { |x| Source.from_dynamic!(x) }, armor_type_id: d.fetch("armorTypeId"), gear_type_id: d.fetch("gearTypeId"), grouped_id: d.fetch("groupedId"), can_be_added_to_inventory: d.fetch("canBeAddedToInventory"), is_container: d.fetch("isContainer"), is_custom_item: d.fetch("isCustomItem"), ) end |
.from_json!(json) ⇒ Object
3509 3510 3511 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3509 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3513 def to_dynamic { "id" => id, "baseTypeId" => base_type_id, "entityTypeId" => entity_type_id, "definitionKey" => definition_key, "canEquip" => can_equip, "magic" => magic, "name" => definition_name, "snippet" => snippet, "weight" => weight, "weightMultiplier" => weight_multiplier, "capacity" => capacity, "capacityWeight" => capacity_weight, "type" => definition_type, "description" => description, "canAttune" => can_attune, "attunementDescription" => attunement_description, "rarity" => rarity, "isHomebrew" => is_homebrew, "version" => version, "sourceId" => source_id, "sourcePageNumber" => source_page_number, "stackable" => stackable, "bundleSize" => bundle_size, "avatarUrl" => avatar_url, "largeAvatarUrl" => large_avatar_url, "filterType" => filter_type, "cost" => cost, "isPack" => is_pack, "tags" => , "grantedModifiers" => granted_modifiers.map { |x| x.to_dynamic }, "subType" => sub_type, "isConsumable" => is_consumable, "weaponBehaviors" => weapon_behaviors.map { |x| x.to_dynamic }, "baseItemId" => base_item_id, "baseArmorName" => base_armor_name, "strengthRequirement" => strength_requirement, "armorClass" => armor_class, "stealthCheck" => stealth_check, "damage" => damage&.to_dynamic, "damageType" => damage_type, "fixedDamage" => fixed_damage, "properties" => properties&.map { |x| x.to_dynamic }, "attackType" => attack_type, "categoryId" => category_id, "range" => range, "longRange" => long_range, "isMonkWeapon" => is_monk_weapon, "levelInfusionGranted" => level_infusion_granted, "sources" => sources.map { |x| x.to_dynamic }, "armorTypeId" => armor_type_id, "gearTypeId" => gear_type_id, "groupedId" => grouped_id, "canBeAddedToInventory" => can_be_added_to_inventory, "isContainer" => is_container, "isCustomItem" => is_custom_item, } end |
#to_json(options = nil) ⇒ Object
3573 3574 3575 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3573 def to_json( = nil) JSON.generate(to_dynamic, ) end |