Class: DdbRuby::FifthEdition::Modifiers

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



3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3345

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

.from_json!(json) ⇒ Object



3357
3358
3359
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3357

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

Instance Method Details

#to_dynamicObject



3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3361

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

#to_json(options = nil) ⇒ Object



3372
3373
3374
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3372

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