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
3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3225 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
3237 3238 3239 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3237 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3241 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
3252 3253 3254 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 3252 def to_json( = nil) JSON.generate(to_dynamic, ) end |