Class: DdbRuby::FifthEdition::Definition1

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



3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3218

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                 d.fetch("id"),
    entity_type_id:     d.fetch("entityTypeId"),
    definition_key:     d.fetch("definitionKey"),
    definition_name:    d.fetch("name"),
    description:        d.fetch("description"),
    snippet:            d.fetch("snippet"),
    activation:         Activation.from_dynamic!(d.fetch("activation")),
    source_id:          d.fetch("sourceId"),
    source_page_number: d.fetch("sourcePageNumber"),
    creature_rules:     d.fetch("creatureRules"),
    prerequisites:      d.fetch("prerequisites").map { |x| Prerequisite.from_dynamic!(x) },
    is_homebrew:        d.fetch("isHomebrew"),
    sources:            d.fetch("sources").map { |x| Source.from_dynamic!(x) },
    spell_list_ids:     d.fetch("spellListIds"),
  )
end

.from_json!(json) ⇒ Object



3238
3239
3240
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3238

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

Instance Method Details

#to_dynamicObject



3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3242

def to_dynamic
  {
    "id"               => id,
    "entityTypeId"     => entity_type_id,
    "definitionKey"    => definition_key,
    "name"             => definition_name,
    "description"      => description,
    "snippet"          => snippet,
    "activation"       => activation.to_dynamic,
    "sourceId"         => source_id,
    "sourcePageNumber" => source_page_number,
    "creatureRules"    => creature_rules,
    "prerequisites"    => prerequisites.map { |x| x.to_dynamic },
    "isHomebrew"       => is_homebrew,
    "sources"          => sources.map { |x| x.to_dynamic },
    "spellListIds"     => spell_list_ids,
  }
end

#to_json(options = nil) ⇒ Object



3261
3262
3263
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3261

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