Class: DdbRuby::FifthEdition::ItemElement
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::ItemElement
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1442 def self.from_dynamic!(d) d = Types::Hash[d] new( fixed_value: d.fetch("fixedValue"), id: d.fetch("id"), entity_id: d.fetch("entityId"), entity_type_id: d.fetch("entityTypeId"), background_type: d.fetch("type"), sub_type: d.fetch("subType"), dice: d.fetch("dice") ? HitPointDice.from_dynamic!(d.fetch("dice")) : nil, restriction: d.fetch("restriction"), stat_id: d.fetch("statId"), requires_attunement: d.fetch("requiresAttunement"), duration: d.fetch("duration") ? BackgroundDuration.from_dynamic!(d.fetch("duration")) : nil, friendly_type_name: d.fetch("friendlyTypeName"), friendly_subtype_name: d.fetch("friendlySubtypeName"), is_granted: d.fetch("isGranted"), bonus_types: d.fetch("bonusTypes"), value: d.fetch("value"), available_to_multiclass: d.fetch("availableToMulticlass"), modifier_type_id: d.fetch("modifierTypeId"), modifier_sub_type_id: d.fetch("modifierSubTypeId"), component_id: d.fetch("componentId"), component_type_id: d.fetch("componentTypeId"), die: d["die"] ? HitPointDice.from_dynamic!(d["die"]) : nil, count: d["count"], duration_unit: d["durationUnit"], use_primary_stat: d["usePrimaryStat"], at_higher_levels: d["atHigherLevels"] ? AtHigherLevels.from_dynamic!(d["atHigherLevels"]) : nil, ) end |
.from_json!(json) ⇒ Object
1474 1475 1476 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1474 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1478 def to_dynamic { "fixedValue" => fixed_value, "id" => id, "entityId" => entity_id, "entityTypeId" => entity_type_id, "type" => background_type, "subType" => sub_type, "dice" => dice&.to_dynamic, "restriction" => restriction, "statId" => stat_id, "requiresAttunement" => requires_attunement, "duration" => duration&.to_dynamic, "friendlyTypeName" => friendly_type_name, "friendlySubtypeName" => friendly_subtype_name, "isGranted" => is_granted, "bonusTypes" => bonus_types, "value" => value, "availableToMulticlass" => available_to_multiclass, "modifierTypeId" => modifier_type_id, "modifierSubTypeId" => modifier_sub_type_id, "componentId" => component_id, "componentTypeId" => component_type_id, "die" => die&.to_dynamic, "count" => count, "durationUnit" => duration_unit, "usePrimaryStat" => use_primary_stat, "atHigherLevels" => at_higher_levels&.to_dynamic, } end |
#to_json(options = nil) ⇒ Object
1509 1510 1511 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1509 def to_json( = nil) JSON.generate(to_dynamic, ) end |