Class: DdbRuby::FifthEdition::DefinitionClassFeature

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



2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2056

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                 d.fetch("id"),
    class_feature_name: d.fetch("name"),
    prerequisite:       d.fetch("prerequisite"),
    description:        d.fetch("description"),
    required_level:     d.fetch("requiredLevel"),
    display_order:      d.fetch("displayOrder"),
  )
end

.from_json!(json) ⇒ Object



2068
2069
2070
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2068

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

Instance Method Details

#to_dynamicObject



2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2072

def to_dynamic
  {
    "id"            => id,
    "name"          => class_feature_name,
    "prerequisite"  => prerequisite,
    "description"   => description,
    "requiredLevel" => required_level,
    "displayOrder"  => display_order,
  }
end

#to_json(options = nil) ⇒ Object



2083
2084
2085
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2083

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