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



2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2384

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") ? HitPointDice.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



2415
2416
2417
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2415

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

Instance Method Details

#to_dynamicObject



2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2419

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



2449
2450
2451
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2449

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