Class: DdbRuby::FifthEdition::PrerequisiteMapping

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



2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2253

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                        d.fetch("id"),
    entity_id:                 d.fetch("entityId"),
    entity_type_id:            d.fetch("entityTypeId"),
    prerequisite_mapping_type: d.fetch("type"),
    sub_type:                  d.fetch("subType"),
    value:                     d.fetch("value"),
    friendly_type_name:        d.fetch("friendlyTypeName"),
    friendly_sub_type_name:    d.fetch("friendlySubTypeName"),
  )
end

.from_json!(json) ⇒ Object



2267
2268
2269
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2267

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

Instance Method Details

#to_dynamicObject



2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2271

def to_dynamic
  {
    "id"                  => id,
    "entityId"            => entity_id,
    "entityTypeId"        => entity_type_id,
    "type"                => prerequisite_mapping_type,
    "subType"             => sub_type,
    "value"               => value,
    "friendlyTypeName"    => friendly_type_name,
    "friendlySubTypeName" => friendly_sub_type_name,
  }
end

#to_json(options = nil) ⇒ Object



2284
2285
2286
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2284

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