Class: DdbRuby::FifthEdition::AtHigherLevels

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



1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1214

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    higher_level_definitions: d.fetch("higherLevelDefinitions").map { |x| HigherLevelDefinition.from_dynamic!(x) },
    additional_attacks:       d.fetch("additionalAttacks"),
    additional_targets:       d.fetch("additionalTargets"),
    area_of_effect:           d.fetch("areaOfEffect"),
    duration:                 d.fetch("duration"),
    creatures:                d.fetch("creatures"),
    special:                  d.fetch("special"),
    points:                   d.fetch("points"),
    range:                    d.fetch("range"),
  )
end

.from_json!(json) ⇒ Object



1229
1230
1231
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1229

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

Instance Method Details

#to_dynamicObject



1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1233

def to_dynamic
  {
    "higherLevelDefinitions" => higher_level_definitions.map { |x| x.to_dynamic },
    "additionalAttacks"      => additional_attacks,
    "additionalTargets"      => additional_targets,
    "areaOfEffect"           => area_of_effect,
    "duration"               => duration,
    "creatures"              => creatures,
    "special"                => special,
    "points"                 => points,
    "range"                  => range,
  }
end

#to_json(options = nil) ⇒ Object



1247
1248
1249
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1247

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