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



1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1970

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



1981
1982
1983
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1981

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

Instance Method Details

#to_dynamicObject



1985
1986
1987
1988
1989
1990
1991
1992
1993
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1985

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

#to_json(options = nil) ⇒ Object



1995
1996
1997
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 1995

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