Class: DdbRuby::FifthEdition::DefinitionDuration

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



1312
1313
1314
1315
1316
1317
1318
1319
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1312

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    duration_interval: d.fetch("durationInterval"),
    duration_unit:     d.fetch("durationUnit"),
    duration_type:     d.fetch("durationType"),
  )
end

.from_json!(json) ⇒ Object



1321
1322
1323
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1321

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

Instance Method Details

#to_dynamicObject



1325
1326
1327
1328
1329
1330
1331
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1325

def to_dynamic
  {
    "durationInterval" => duration_interval,
    "durationUnit"     => duration_unit,
    "durationType"     => duration_type,
  }
end

#to_json(options = nil) ⇒ Object



1333
1334
1335
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1333

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