Class: DdbRuby::FifthEdition::Definition2

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



824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 824

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                 d.fetch("id"),
    entity_type_id:     d.fetch("entityTypeId"),
    definition_name:    d.fetch("name"),
    description:        d.fetch("description"),
    snippet:            d.fetch("snippet"),
    activation:         d.fetch("activation"),
    source_id:          d.fetch("sourceId"),
    source_page_number: d.fetch("sourcePageNumber"),
    creature_rules:     d.fetch("creatureRules"),
    spell_list_ids:     d.fetch("spellListIds"),
  )
end

.from_json!(json) ⇒ Object



840
841
842
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 840

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

Instance Method Details

#to_dynamicObject



844
845
846
847
848
849
850
851
852
853
854
855
856
857
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 844

def to_dynamic
  {
    "id"               => id,
    "entityTypeId"     => entity_type_id,
    "name"             => definition_name,
    "description"      => description,
    "snippet"          => snippet,
    "activation"       => activation,
    "sourceId"         => source_id,
    "sourcePageNumber" => source_page_number,
    "creatureRules"    => creature_rules,
    "spellListIds"     => spell_list_ids,
  }
end

#to_json(options = nil) ⇒ Object



859
860
861
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 859

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