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



509
510
511
512
513
514
515
516
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 509

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



518
519
520
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 518

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

Instance Method Details

#to_dynamicObject



522
523
524
525
526
527
528
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 522

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

#to_json(options = nil) ⇒ Object



530
531
532
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 530

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