Class: DdbRuby::FifthEdition::Modifiers
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::Modifiers
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3693 def self.from_dynamic!(d) d = Types::Hash[d] new( race: d.fetch("race").map { |x| ItemElement.from_dynamic!(x) }, modifiers_class: d.fetch("class").map { |x| ItemElement.from_dynamic!(x) }, background: d.fetch("background").map { |x| ItemElement.from_dynamic!(x) }, item: d.fetch("item").map { |x| ItemElement.from_dynamic!(x) }, feat: d.fetch("feat").map { |x| ItemElement.from_dynamic!(x) }, condition: d.fetch("condition"), ) end |
.from_json!(json) ⇒ Object
3705 3706 3707 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3705 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3709 def to_dynamic { "race" => race.map { |x| x.to_dynamic }, "class" => modifiers_class.map { |x| x.to_dynamic }, "background" => background.map { |x| x.to_dynamic }, "item" => item.map { |x| x.to_dynamic }, "feat" => feat.map { |x| x.to_dynamic }, "condition" => condition, } end |
#to_json(options = nil) ⇒ Object
3720 3721 3722 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3720 def to_json( = nil) JSON.generate(to_dynamic, ) end |