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



2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2245

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



2276
2277
2278
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2276

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

Instance Method Details

#to_dynamicObject



2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2280

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



2310
2311
2312
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2310

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