Class: DdbRuby::FifthEdition::Source

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



478
479
480
481
482
483
484
485
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 478

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    source_id:   d.fetch("sourceId"),
    page_number: d.fetch("pageNumber"),
    source_type: d.fetch("sourceType"),
  )
end

.from_json!(json) ⇒ Object



487
488
489
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 487

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

Instance Method Details

#to_dynamicObject



491
492
493
494
495
496
497
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 491

def to_dynamic
  {
    "sourceId"   => source_id,
    "pageNumber" => page_number,
    "sourceType" => source_type,
  }
end

#to_json(options = nil) ⇒ Object



499
500
501
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 499

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