Class: DdbRuby::FifthEdition::Normal

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



3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3912

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    walk:   d.fetch("walk"),
    fly:    d.fetch("fly"),
    burrow: d.fetch("burrow"),
    swim:   d.fetch("swim"),
    climb:  d.fetch("climb"),
  )
end

.from_json!(json) ⇒ Object



3923
3924
3925
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3923

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

Instance Method Details

#to_dynamicObject



3927
3928
3929
3930
3931
3932
3933
3934
3935
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3927

def to_dynamic
  {
    "walk"   => walk,
    "fly"    => fly,
    "burrow" => burrow,
    "swim"   => swim,
    "climb"  => climb,
  }
end

#to_json(options = nil) ⇒ Object



3937
3938
3939
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3937

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