Class: DdbRuby::FifthEdition::CharacterBackground

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



653
654
655
656
657
658
659
660
661
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 653

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    has_custom_background: d.fetch("hasCustomBackground"),
    definition:            d.fetch("definition") ? BackgroundDefinition.from_dynamic!(d.fetch("definition")) : nil,
    definition_id:         d.fetch("definitionId"),
    custom_background:     CustomBackground.from_dynamic!(d.fetch("customBackground")),
  )
end

.from_json!(json) ⇒ Object



663
664
665
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 663

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

Instance Method Details

#to_dynamicObject



667
668
669
670
671
672
673
674
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 667

def to_dynamic
  {
    "hasCustomBackground" => has_custom_background,
    "definition"          => definition&.to_dynamic,
    "definitionId"        => definition_id,
    "customBackground"    => custom_background.to_dynamic,
  }
end

#to_json(options = nil) ⇒ Object



676
677
678
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 676

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