Class: DdbRuby::FifthEdition::Spells

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



4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4382

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    race:         d.fetch("race").map { |x| RaceElement.from_dynamic!(x) },
    spells_class: d.fetch("class").map { |x| SpellsClass.from_dynamic!(x) },
    background:   d.fetch("background"),
    item:         d.fetch("item").map { |x| Item.from_dynamic!(x) },
    feat:         d.fetch("feat").map { |x| RaceElement.from_dynamic!(x) },
  )
end

.from_json!(json) ⇒ Object



4393
4394
4395
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4393

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

Instance Method Details

#to_dynamicObject



4397
4398
4399
4400
4401
4402
4403
4404
4405
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4397

def to_dynamic
  {
    "race"       => race.map { |x| x.to_dynamic },
    "class"      => spells_class.map { |x| x.to_dynamic },
    "background" => background,
    "item"       => item.map { |x| x.to_dynamic },
    "feat"       => feat.map { |x| x.to_dynamic },
  }
end

#to_json(options = nil) ⇒ Object



4407
4408
4409
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 4407

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