Class: DdbRuby::FifthEdition::DeathSaves

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



3011
3012
3013
3014
3015
3016
3017
3018
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3011

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    fail_count:    d.fetch("failCount"),
    success_count: d.fetch("successCount"),
    is_stabilized: d.fetch("isStabilized"),
  )
end

.from_json!(json) ⇒ Object



3020
3021
3022
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3020

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

Instance Method Details

#to_dynamicObject



3024
3025
3026
3027
3028
3029
3030
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3024

def to_dynamic
  {
    "failCount"    => fail_count,
    "successCount" => success_count,
    "isStabilized" => is_stabilized,
  }
end

#to_json(options = nil) ⇒ Object



3032
3033
3034
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3032

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