Class: DdbRuby::FifthEdition::CustomItem
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::CustomItem
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2972 def self.from_dynamic!(d) d = Types::Hash[d] new( id: d.fetch("id"), custom_item_name: d.fetch("name"), description: d.fetch("description"), weight: d.fetch("weight"), cost: d.fetch("cost"), quantity: d.fetch("quantity"), notes: d.fetch("notes"), ) end |
.from_json!(json) ⇒ Object
2985 2986 2987 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2985 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2989 def to_dynamic { "id" => id, "name" => custom_item_name, "description" => description, "weight" => weight, "cost" => cost, "quantity" => quantity, "notes" => notes, } end |
#to_json(options = nil) ⇒ Object
3001 3002 3003 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3001 def to_json( = nil) JSON.generate(to_dynamic, ) end |