Class: DdbRuby::FifthEdition::ClassLimitedUse

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



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 126

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    limited_use_name:           d.fetch("name"),
    stat_modifier_uses_id:      d.fetch("statModifierUsesId"),
    reset_type:                 d.fetch("resetType"),
    number_used:                d.fetch("numberUsed"),
    min_number_consumed:        d.fetch("minNumberConsumed"),
    max_number_consumed:        d.fetch("maxNumberConsumed"),
    max_uses:                   d.fetch("maxUses"),
    operator:                   d.fetch("operator"),
    use_proficiency_bonus:      d.fetch("useProficiencyBonus"),
    proficiency_bonus_operator: d.fetch("proficiencyBonusOperator"),
    reset_dice:                 d.fetch("resetDice"),
  )
end

.from_json!(json) ⇒ Object



143
144
145
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 143

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

Instance Method Details

#to_dynamicObject



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 147

def to_dynamic
  {
    "name"                     => limited_use_name,
    "statModifierUsesId"       => stat_modifier_uses_id,
    "resetType"                => reset_type,
    "numberUsed"               => number_used,
    "minNumberConsumed"        => min_number_consumed,
    "maxNumberConsumed"        => max_number_consumed,
    "maxUses"                  => max_uses,
    "operator"                 => operator,
    "useProficiencyBonus"      => use_proficiency_bonus,
    "proficiencyBonusOperator" => proficiency_bonus_operator,
    "resetDice"                => reset_dice,
  }
end

#to_json(options = nil) ⇒ Object



163
164
165
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 163

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