Class: DdbRuby::FifthEdition::Traits

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



4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4423

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    personality_traits: d.fetch("personalityTraits"),
    ideals:             d.fetch("ideals"),
    bonds:              d.fetch("bonds"),
    flaws:              d.fetch("flaws"),
    appearance:         d.fetch("appearance"),
  )
end

.from_json!(json) ⇒ Object



4434
4435
4436
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4434

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

Instance Method Details

#to_dynamicObject



4438
4439
4440
4441
4442
4443
4444
4445
4446
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4438

def to_dynamic
  {
    "personalityTraits" => personality_traits,
    "ideals"            => ideals,
    "bonds"             => bonds,
    "flaws"             => flaws,
    "appearance"        => appearance,
  }
end

#to_json(options = nil) ⇒ Object



4448
4449
4450
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4448

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