Class: DdbRuby::FifthEdition::SpellDefinition

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/ddb_ruby/fifth_edition/structs.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1650

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                       d.fetch("id"),
    definition_key:           d.fetch("definitionKey"),
    definition_name:          d.fetch("name"),
    level:                    d.fetch("level"),
    school:                   d.fetch("school"),
    duration:                 DefinitionDuration.from_dynamic!(d.fetch("duration")),
    activation:               Activation.from_dynamic!(d.fetch("activation")),
    range:                    DefinitionRange.from_dynamic!(d.fetch("range")),
    as_part_of_weapon_attack: d.fetch("asPartOfWeaponAttack"),
    description:              d.fetch("description"),
    snippet:                  d.fetch("snippet"),
    concentration:            d.fetch("concentration"),
    ritual:                   d.fetch("ritual"),
    range_area:               d.fetch("rangeArea"),
    damage_effect:            d.fetch("damageEffect"),
    components:               d.fetch("components"),
    components_description:   d.fetch("componentsDescription"),
    save_dc_ability_id:       d.fetch("saveDcAbilityId"),
    healing:                  d.fetch("healing"),
    healing_dice:             d.fetch("healingDice"),
    temp_hp_dice:             d.fetch("tempHpDice"),
    attack_type:              d.fetch("attackType"),
    can_cast_at_higher_level: d.fetch("canCastAtHigherLevel"),
    is_homebrew:              d.fetch("isHomebrew"),
    version:                  d.fetch("version"),
    source_id:                d.fetch("sourceId"),
    source_page_number:       d.fetch("sourcePageNumber"),
    requires_saving_throw:    d.fetch("requiresSavingThrow"),
    requires_attack_roll:     d.fetch("requiresAttackRoll"),
    at_higher_levels:         AtHigherLevels.from_dynamic!(d.fetch("atHigherLevels")),
    modifiers:                d.fetch("modifiers").map { |x| ItemElement.from_dynamic!(x) },
    conditions:               d.fetch("conditions").map { |x| Condition.from_dynamic!(x) },
    tags:                     d.fetch("tags"),
    casting_time_description: d.fetch("castingTimeDescription"),
    scale_type:               d.fetch("scaleType"),
    sources:                  d.fetch("sources").map { |x| Source.from_dynamic!(x) },
    spell_groups:             d.fetch("spellGroups"),
  )
end

.from_json!(json) ⇒ Object



1693
1694
1695
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1693

def self.from_json!(json)
  from_dynamic!(JSON.parse(json))
end

Instance Method Details

#to_dynamicObject



1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1697

def to_dynamic
  {
    "id"                     => id,
    "definitionKey"          => definition_key,
    "name"                   => definition_name,
    "level"                  => level,
    "school"                 => school,
    "duration"               => duration.to_dynamic,
    "activation"             => activation.to_dynamic,
    "range"                  => range.to_dynamic,
    "asPartOfWeaponAttack"   => as_part_of_weapon_attack,
    "description"            => description,
    "snippet"                => snippet,
    "concentration"          => concentration,
    "ritual"                 => ritual,
    "rangeArea"              => range_area,
    "damageEffect"           => damage_effect,
    "components"             => components,
    "componentsDescription"  => components_description,
    "saveDcAbilityId"        => save_dc_ability_id,
    "healing"                => healing,
    "healingDice"            => healing_dice,
    "tempHpDice"             => temp_hp_dice,
    "attackType"             => attack_type,
    "canCastAtHigherLevel"   => can_cast_at_higher_level,
    "isHomebrew"             => is_homebrew,
    "version"                => version,
    "sourceId"               => source_id,
    "sourcePageNumber"       => source_page_number,
    "requiresSavingThrow"    => requires_saving_throw,
    "requiresAttackRoll"     => requires_attack_roll,
    "atHigherLevels"         => at_higher_levels.to_dynamic,
    "modifiers"              => modifiers.map { |x| x.to_dynamic },
    "conditions"             => conditions.map { |x| x.to_dynamic },
    "tags"                   => tags,
    "castingTimeDescription" => casting_time_description,
    "scaleType"              => scale_type,
    "sources"                => sources.map { |x| x.to_dynamic },
    "spellGroups"            => spell_groups,
  }
end

#to_json(options = nil) ⇒ Object



1739
1740
1741
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1739

def to_json(options = nil)
  JSON.generate(to_dynamic, options)
end