Class: DdbRuby::FifthEdition::BonusStatElement

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



686
687
688
689
690
691
692
693
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 686

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:        d.fetch("id"),
    stat_name: d.fetch("name"),
    value:     d.fetch("value"),
  )
end

.from_json!(json) ⇒ Object



695
696
697
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 695

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

Instance Method Details

#to_dynamicObject



699
700
701
702
703
704
705
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 699

def to_dynamic
  {
    "id"    => id,
    "name"  => stat_name,
    "value" => value,
  }
end

#to_json(options = nil) ⇒ Object



707
708
709
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 707

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