Class: DdbRuby::FifthEdition::Bond

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



413
414
415
416
417
418
419
420
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 413

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:          d.fetch("id"),
    description: d.fetch("description"),
    dice_roll:   d.fetch("diceRoll"),
  )
end

.from_json!(json) ⇒ Object



422
423
424
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 422

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

Instance Method Details

#to_dynamicObject



426
427
428
429
430
431
432
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 426

def to_dynamic
  {
    "id"          => id,
    "description" => description,
    "diceRoll"    => dice_roll,
  }
end

#to_json(options = nil) ⇒ Object



434
435
436
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 434

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