Class: DdbRuby::FifthEdition::ChoiceDefinition

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



1074
1075
1076
1077
1078
1079
1080
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1074

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                        d.fetch("id"),
    choice_definition_options: d.fetch("options").map { |x| Option.from_dynamic!(x) },
  )
end

.from_json!(json) ⇒ Object



1082
1083
1084
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1082

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

Instance Method Details

#to_dynamicObject



1086
1087
1088
1089
1090
1091
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1086

def to_dynamic
  {
    "id"      => id,
    "options" => choice_definition_options.map { |x| x.to_dynamic },
  }
end

#to_json(options = nil) ⇒ Object



1093
1094
1095
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1093

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