Class: DdbRuby::FifthEdition::HigherLevelDefinition
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::HigherLevelDefinition
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1173 def self.from_dynamic!(d) d = Types::Hash[d] new( level: d.fetch("level"), type_id: d.fetch("typeId"), dice: d.fetch("dice") ? HitPointDice.from_dynamic!(d.fetch("dice")) : nil, value: d.fetch("value"), details: d.fetch("details"), ) end |
.from_json!(json) ⇒ Object
1184 1185 1186 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1184 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
1188 1189 1190 1191 1192 1193 1194 1195 1196 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1188 def to_dynamic { "level" => level, "typeId" => type_id, "dice" => dice&.to_dynamic, "value" => value, "details" => details, } end |
#to_json(options = nil) ⇒ Object
1198 1199 1200 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1198 def to_json( = nil) JSON.generate(to_dynamic, ) end |