Class: DdbRuby::FifthEdition::Option

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



1044
1045
1046
1047
1048
1049
1050
1051
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1044

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

.from_json!(json) ⇒ Object



1053
1054
1055
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1053

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

Instance Method Details

#to_dynamicObject



1057
1058
1059
1060
1061
1062
1063
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1057

def to_dynamic
  {
    "id"          => id,
    "label"       => label,
    "description" => description,
  }
end

#to_json(options = nil) ⇒ Object



1065
1066
1067
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1065

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