Class: DdbRuby::FifthEdition::LevelScale

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



1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1850

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:          d.fetch("id"),
    level:       d.fetch("level"),
    description: d.fetch("description"),
    dice:        d.fetch("dice") ? Die.from_dynamic!(d.fetch("dice")) : nil,
    fixed_value: d.fetch("fixedValue"),
  )
end

.from_json!(json) ⇒ Object



1861
1862
1863
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1861

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

Instance Method Details

#to_dynamicObject



1865
1866
1867
1868
1869
1870
1871
1872
1873
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1865

def to_dynamic
  {
    "id"          => id,
    "level"       => level,
    "description" => description,
    "dice"        => dice&.to_dynamic,
    "fixedValue"  => fixed_value,
  }
end

#to_json(options = nil) ⇒ Object



1875
1876
1877
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1875

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