Class: DdbRuby::FifthEdition::ActionsClass

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



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 244

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    component_id:             d.fetch("componentId"),
    component_type_id:        d.fetch("componentTypeId"),
    id:                       d.fetch("id"),
    entity_type_id:           d.fetch("entityTypeId"),
    limited_use:              d.fetch("limitedUse") ? ClassLimitedUse.from_dynamic!(d.fetch("limitedUse")) : nil,
    class_name:               d.fetch("name"),
    description:              d.fetch("description"),
    snippet:                  d.fetch("snippet"),
    ability_modifier_stat_id: d.fetch("abilityModifierStatId"),
    on_miss_description:      d.fetch("onMissDescription"),
    save_fail_description:    d.fetch("saveFailDescription"),
    save_success_description: d.fetch("saveSuccessDescription"),
    save_stat_id:             d.fetch("saveStatId"),
    fixed_save_dc:            d.fetch("fixedSaveDc"),
    attack_type_range:        d.fetch("attackTypeRange"),
    action_type:              d.fetch("actionType"),
    attack_subtype:           d.fetch("attackSubtype"),
    dice:                     d.fetch("dice") ? HitPointDice.from_dynamic!(d.fetch("dice")) : nil,
    value:                    d.fetch("value"),
    damage_type_id:           d.fetch("damageTypeId"),
    is_martial_arts:          d.fetch("isMartialArts"),
    is_proficient:            d.fetch("isProficient"),
    spell_range_type:         d.fetch("spellRangeType"),
    display_as_attack:        d.fetch("displayAsAttack"),
    range:                    Range1.from_dynamic!(d.fetch("range")),
    activation:               Activation.from_dynamic!(d.fetch("activation")),
    number_of_targets:        d.fetch("numberOfTargets"),
    fixed_to_hit:             d.fetch("fixedToHit"),
    ammunition:               d.fetch("ammunition"),
  )
end

.from_json!(json) ⇒ Object



279
280
281
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 279

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

Instance Method Details

#to_dynamicObject



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 283

def to_dynamic
  {
    "componentId"            => component_id,
    "componentTypeId"        => component_type_id,
    "id"                     => id,
    "entityTypeId"           => entity_type_id,
    "limitedUse"             => limited_use&.to_dynamic,
    "name"                   => class_name,
    "description"            => description,
    "snippet"                => snippet,
    "abilityModifierStatId"  => ability_modifier_stat_id,
    "onMissDescription"      => on_miss_description,
    "saveFailDescription"    => save_fail_description,
    "saveSuccessDescription" => save_success_description,
    "saveStatId"             => save_stat_id,
    "fixedSaveDc"            => fixed_save_dc,
    "attackTypeRange"        => attack_type_range,
    "actionType"             => action_type,
    "attackSubtype"          => attack_subtype,
    "dice"                   => dice&.to_dynamic,
    "value"                  => value,
    "damageTypeId"           => damage_type_id,
    "isMartialArts"          => is_martial_arts,
    "isProficient"           => is_proficient,
    "spellRangeType"         => spell_range_type,
    "displayAsAttack"        => display_as_attack,
    "range"                  => range.to_dynamic,
    "activation"             => activation.to_dynamic,
    "numberOfTargets"        => number_of_targets,
    "fixedToHit"             => fixed_to_hit,
    "ammunition"             => ammunition,
  }
end

#to_json(options = nil) ⇒ Object



317
318
319
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 317

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