Class: DdbRuby::FifthEdition::Organization

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



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

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                d.fetch("id"),
    organization_name: d.fetch("name"),
    description:       d.fetch("description"),
    notes:             d["notes"],
  )
end

.from_json!(json) ⇒ Object



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

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

Instance Method Details

#to_dynamicObject



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

def to_dynamic
  {
    "id"          => id,
    "name"        => organization_name,
    "description" => description,
    "notes"       => notes,
  }
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