Class: DdbRuby::FifthEdition::CreatureDefinition
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- DdbRuby::FifthEdition::CreatureDefinition
- Defined in:
- lib/ddb_ruby/fifth_edition/structs.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.from_dynamic!(d) ⇒ Object
2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2763 def self.from_dynamic!(d) d = Types::Hash[d] new( id: d.fetch("id"), entity_type_id: d.fetch("entityTypeId"), definition_name: d.fetch("name"), alignment_id: d.fetch("alignmentId"), size_id: d.fetch("sizeId"), type_id: d.fetch("typeId"), armor_class: d.fetch("armorClass"), armor_class_description: d.fetch("armorClassDescription"), average_hit_points: d.fetch("averageHitPoints"), hit_point_dice: HitPointDice.from_dynamic!(d.fetch("hitPointDice")), movements: d.fetch("movements").map { |x| Movement.from_dynamic!(x) }, passive_perception: d.fetch("passivePerception"), is_homebrew: d.fetch("isHomebrew"), challenge_rating_id: d.fetch("challengeRatingId"), source_id: d.fetch("sourceId"), source_page_number: d.fetch("sourcePageNumber"), is_legendary: d.fetch("isLegendary"), is_mythic: d.fetch("isMythic"), has_lair: d.fetch("hasLair"), avatar_url: d.fetch("avatarUrl"), large_avatar_url: d.fetch("largeAvatarUrl"), basic_avatar_url: d.fetch("basicAvatarUrl"), version: d.fetch("version"), swarm: d.fetch("swarm"), sub_types: d.fetch("subTypes"), environments: d.fetch("environments"), tags: d.fetch("tags"), sources: d.fetch("sources").map { |x| Source.from_dynamic!(x) }, stats: d.fetch("stats").map { |x| DefinitionStat.from_dynamic!(x) }, senses: d.fetch("senses").map { |x| Sense.from_dynamic!(x) }, damage_adjustments: d.fetch("damageAdjustments"), condition_immunities: d.fetch("conditionImmunities"), saving_throws: d.fetch("savingThrows").map { |x| SavingThrow.from_dynamic!(x) }, skills: d.fetch("skills").map { |x| Skill.from_dynamic!(x) }, languages: d.fetch("languages").map { |x| Language.from_dynamic!(x) }, special_traits_description: d.fetch("specialTraitsDescription"), actions_description: d.fetch("actionsDescription"), reactions_description: d.fetch("reactionsDescription"), legendary_actions_description: d.fetch("legendaryActionsDescription"), mythic_actions_description: d.fetch("mythicActionsDescription"), bonus_actions_description: d.fetch("bonusActionsDescription"), characteristics_description: d.fetch("characteristicsDescription"), lair_description: d.fetch("lairDescription"), language_description: d.fetch("languageDescription"), language_note: d.fetch("languageNote"), hide_cr: d.fetch("hideCr"), is_legacy: d.fetch("isLegacy"), ) end |
.from_json!(json) ⇒ Object
2816 2817 2818 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2816 def self.from_json!(json) from_dynamic!(JSON.parse(json)) end |
Instance Method Details
#to_dynamic ⇒ Object
2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2820 def to_dynamic { "id" => id, "entityTypeId" => entity_type_id, "name" => definition_name, "alignmentId" => alignment_id, "sizeId" => size_id, "typeId" => type_id, "armorClass" => armor_class, "armorClassDescription" => armor_class_description, "averageHitPoints" => average_hit_points, "hitPointDice" => hit_point_dice.to_dynamic, "movements" => movements.map { |x| x.to_dynamic }, "passivePerception" => passive_perception, "isHomebrew" => is_homebrew, "challengeRatingId" => , "sourceId" => source_id, "sourcePageNumber" => source_page_number, "isLegendary" => is_legendary, "isMythic" => is_mythic, "hasLair" => has_lair, "avatarUrl" => avatar_url, "largeAvatarUrl" => large_avatar_url, "basicAvatarUrl" => basic_avatar_url, "version" => version, "swarm" => swarm, "subTypes" => sub_types, "environments" => environments, "tags" => , "sources" => sources.map { |x| x.to_dynamic }, "stats" => stats.map { |x| x.to_dynamic }, "senses" => senses.map { |x| x.to_dynamic }, "damageAdjustments" => damage_adjustments, "conditionImmunities" => condition_immunities, "savingThrows" => saving_throws.map { |x| x.to_dynamic }, "skills" => skills.map { |x| x.to_dynamic }, "languages" => languages.map { |x| x.to_dynamic }, "specialTraitsDescription" => special_traits_description, "actionsDescription" => actions_description, "reactionsDescription" => reactions_description, "legendaryActionsDescription" => legendary_actions_description, "mythicActionsDescription" => mythic_actions_description, "bonusActionsDescription" => bonus_actions_description, "characteristicsDescription" => characteristics_description, "lairDescription" => lair_description, "languageDescription" => language_description, "languageNote" => language_note, "hideCr" => hide_cr, "isLegacy" => is_legacy, } end |
#to_json(options = nil) ⇒ Object
2872 2873 2874 |
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 2872 def to_json( = nil) JSON.generate(to_dynamic, ) end |