Class: DdbRuby::FifthEdition::Spell

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



1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1771

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    override_save_dc:          d.fetch("overrideSaveDc"),
    limited_use:               d.fetch("limitedUse"),
    id:                        d.fetch("id"),
    entity_type_id:            d.fetch("entityTypeId"),
    definition:                SpellDefinition.from_dynamic!(d.fetch("definition")),
    definition_id:             d.fetch("definitionId"),
    prepared:                  d.fetch("prepared"),
    counts_as_known_spell:     d.fetch("countsAsKnownSpell"),
    uses_spell_slot:           d.fetch("usesSpellSlot"),
    cast_at_level:             d.fetch("castAtLevel"),
    always_prepared:           d.fetch("alwaysPrepared"),
    restriction:               d.fetch("restriction"),
    spell_casting_ability_id:  d.fetch("spellCastingAbilityId"),
    display_as_attack:         d.fetch("displayAsAttack"),
    additional_description:    d.fetch("additionalDescription"),
    cast_only_as_ritual:       d.fetch("castOnlyAsRitual"),
    ritual_casting_type:       d.fetch("ritualCastingType"),
    range:                     DefinitionRange.from_dynamic!(d.fetch("range")),
    activation:                Activation.from_dynamic!(d.fetch("activation")),
    base_level_at_will:        d.fetch("baseLevelAtWill"),
    at_will_limited_use_level: d.fetch("atWillLimitedUseLevel"),
    is_signature_spell:        d.fetch("isSignatureSpell"),
    component_id:              d.fetch("componentId"),
    component_type_id:         d.fetch("componentTypeId"),
    spell_list_id:             d.fetch("spellListId"),
  )
end

.from_json!(json) ⇒ Object



1802
1803
1804
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1802

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

Instance Method Details

#to_dynamicObject



1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1806

def to_dynamic
  {
    "overrideSaveDc"        => override_save_dc,
    "limitedUse"            => limited_use,
    "id"                    => id,
    "entityTypeId"          => entity_type_id,
    "definition"            => definition.to_dynamic,
    "definitionId"          => definition_id,
    "prepared"              => prepared,
    "countsAsKnownSpell"    => counts_as_known_spell,
    "usesSpellSlot"         => uses_spell_slot,
    "castAtLevel"           => cast_at_level,
    "alwaysPrepared"        => always_prepared,
    "restriction"           => restriction,
    "spellCastingAbilityId" => spell_casting_ability_id,
    "displayAsAttack"       => display_as_attack,
    "additionalDescription" => additional_description,
    "castOnlyAsRitual"      => cast_only_as_ritual,
    "ritualCastingType"     => ritual_casting_type,
    "range"                 => range.to_dynamic,
    "activation"            => activation.to_dynamic,
    "baseLevelAtWill"       => base_level_at_will,
    "atWillLimitedUseLevel" => at_will_limited_use_level,
    "isSignatureSpell"      => is_signature_spell,
    "componentId"           => component_id,
    "componentTypeId"       => component_type_id,
    "spellListId"           => spell_list_id,
  }
end

#to_json(options = nil) ⇒ Object



1836
1837
1838
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1836

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