Class: DdbRuby::FifthEdition::SubclassDefinitionClass

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



2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2365

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                       d.fetch("id"),
    definition_key:           d.fetch("definitionKey"),
    definition_name:          d.fetch("name"),
    description:              d.fetch("description"),
    equipment_description:    d.fetch("equipmentDescription"),
    parent_class_id:          d.fetch("parentClassId"),
    avatar_url:               d.fetch("avatarUrl"),
    large_avatar_url:         d.fetch("largeAvatarUrl"),
    portrait_avatar_url:      d.fetch("portraitAvatarUrl"),
    more_details_url:         d.fetch("moreDetailsUrl"),
    spell_casting_ability_id: d.fetch("spellCastingAbilityId"),
    sources:                  d.fetch("sources").map { |x| Source.from_dynamic!(x) },
    class_features:           d.fetch("classFeatures").map { |x| DefinitionClassFeature.from_dynamic!(x) },
    hit_dice:                 d.fetch("hitDice"),
    wealth_dice:              d.fetch("wealthDice") ? Die.from_dynamic!(d.fetch("wealthDice")) : nil,
    can_cast_spells:          d.fetch("canCastSpells"),
    knows_all_spells:         d.fetch("knowsAllSpells"),
    spell_prepare_type:       d.fetch("spellPrepareType"),
    spell_container_name:     d.fetch("spellContainerName"),
    source_page_number:       d.fetch("sourcePageNumber"),
    subclass_definition:      d.fetch("subclassDefinition"),
    is_homebrew:              d.fetch("isHomebrew"),
    primary_abilities:        d.fetch("primaryAbilities"),
    spell_rules:              d.fetch("spellRules") ? SpellRules.from_dynamic!(d.fetch("spellRules")) : nil,
    prerequisites:            d.fetch("prerequisites")&.map { |x| Prerequisite.from_dynamic!(x) },
  )
end

.from_json!(json) ⇒ Object



2396
2397
2398
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2396

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

Instance Method Details

#to_dynamicObject



2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2400

def to_dynamic
  {
    "id"                    => id,
    "definitionKey"         => definition_key,
    "name"                  => definition_name,
    "description"           => description,
    "equipmentDescription"  => equipment_description,
    "parentClassId"         => parent_class_id,
    "avatarUrl"             => avatar_url,
    "largeAvatarUrl"        => large_avatar_url,
    "portraitAvatarUrl"     => portrait_avatar_url,
    "moreDetailsUrl"        => more_details_url,
    "spellCastingAbilityId" => spell_casting_ability_id,
    "sources"               => sources.map { |x| x.to_dynamic },
    "classFeatures"         => class_features.map { |x| x.to_dynamic },
    "hitDice"               => hit_dice,
    "wealthDice"            => wealth_dice&.to_dynamic,
    "canCastSpells"         => can_cast_spells,
    "knowsAllSpells"        => knows_all_spells,
    "spellPrepareType"      => spell_prepare_type,
    "spellContainerName"    => spell_container_name,
    "sourcePageNumber"      => source_page_number,
    "subclassDefinition"    => subclass_definition,
    "isHomebrew"            => is_homebrew,
    "primaryAbilities"      => primary_abilities,
    "spellRules"            => spell_rules&.to_dynamic,
    "prerequisites"         => prerequisites&.map { |x| x.to_dynamic },
  }
end

#to_json(options = nil) ⇒ Object



2430
2431
2432
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2430

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