Class: DdbRuby::FifthEdition::Actions
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::Actions
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
329 330 331 332 333 334 335 336 337 338 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 329 def self.from_dynamic!(d) d = Types::Hash[d] new( race: d.fetch("race").map { |x| ActionsClass.from_dynamic!(x) }, actions_class: d.fetch("class").map { |x| ActionsClass.from_dynamic!(x) }, background: d.fetch("background"), item: d.fetch("item"), feat: d.fetch("feat").map { |x| ActionsClass.from_dynamic!(x) }, ) end |
.from_json!(json) ⇒ Object
340 341 342 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 340 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
344 345 346 347 348 349 350 351 352 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 344 def to_dynamic { "race" => race.map { |x| x.to_dynamic }, "class" => actions_class.map { |x| x.to_dynamic }, "background" => background, "item" => item, "feat" => feat.map { |x| x.to_dynamic }, } end |
#to_json(options = nil) ⇒ Object
354 355 356 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 354 def to_json( = nil) JSON.generate(to_dynamic, ) end |