Class: DdbRuby::FifthEdition::CharacterValue

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



941
942
943
944
945
946
947
948
949
950
951
952
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 941

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    type_id:         d.fetch("typeId"),
    value:           d.fetch("value"),
    notes:           d.fetch("notes"),
    value_id:        d.fetch("valueId"),
    value_type_id:   d.fetch("valueTypeId"),
    context_id:      d.fetch("contextId"),
    context_type_id: d.fetch("contextTypeId"),
  )
end

.from_json!(json) ⇒ Object



954
955
956
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 954

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

Instance Method Details

#to_dynamicObject



958
959
960
961
962
963
964
965
966
967
968
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 958

def to_dynamic
  {
    "typeId"        => type_id,
    "value"         => value,
    "notes"         => notes,
    "valueId"       => value_id,
    "valueTypeId"   => value_type_id,
    "contextId"     => context_id,
    "contextTypeId" => context_type_id,
  }
end

#to_json(options = nil) ⇒ Object



970
971
972
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 970

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