Class: DdbRuby::FifthEdition::BackgroundDefinition

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



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 567

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    id:                                    d.fetch("id"),
    entity_type_id:                        d.fetch("entityTypeId"),
    definition_key:                        d.fetch("definitionKey"),
    definition_name:                       d.fetch("name"),
    description:                           d.fetch("description"),
    snippet:                               d.fetch("snippet"),
    short_description:                     d.fetch("shortDescription"),
    skill_proficiencies_description:       d.fetch("skillProficienciesDescription"),
    tool_proficiencies_description:        d.fetch("toolProficienciesDescription"),
    languages_description:                 d.fetch("languagesDescription"),
    equipment_description:                 d.fetch("equipmentDescription"),
    feature_name:                          d.fetch("featureName"),
    feature_description:                   d.fetch("featureDescription"),
    avatar_url:                            d.fetch("avatarUrl"),
    large_avatar_url:                      d.fetch("largeAvatarUrl"),
    suggested_characteristics_description: d.fetch("suggestedCharacteristicsDescription"),
    suggested_proficiencies:               d.fetch("suggestedProficiencies"),
    suggested_languages:                   d.fetch("suggestedLanguages"),
    organization:                          d.fetch("organization") ? Organization.from_dynamic!(d.fetch("organization")) : nil,
    contracts_description:                 d.fetch("contractsDescription"),
    spells_pre_description:                d.fetch("spellsPreDescription"),
    spells_post_description:               d.fetch("spellsPostDescription"),
    personality_traits:                    d.fetch("personalityTraits").map { |x| Bond.from_dynamic!(x) },
    ideals:                                d.fetch("ideals").map { |x| Bond.from_dynamic!(x) },
    bonds:                                 d.fetch("bonds").map { |x| Bond.from_dynamic!(x) },
    flaws:                                 d.fetch("flaws").map { |x| Bond.from_dynamic!(x) },
    is_homebrew:                           d.fetch("isHomebrew"),
    sources:                               d.fetch("sources").map { |x| Source.from_dynamic!(x) },
    spell_list_ids:                        d.fetch("spellListIds"),
    feat_list:                             d.fetch("featList") ? FeatList.from_dynamic!(d.fetch("featList")) : nil,
  )
end

.from_json!(json) ⇒ Object



603
604
605
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 603

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

Instance Method Details

#to_dynamicObject



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 607

def to_dynamic
  {
    "id"                                  => id,
    "entityTypeId"                        => entity_type_id,
    "definitionKey"                       => definition_key,
    "name"                                => definition_name,
    "description"                         => description,
    "snippet"                             => snippet,
    "shortDescription"                    => short_description,
    "skillProficienciesDescription"       => skill_proficiencies_description,
    "toolProficienciesDescription"        => tool_proficiencies_description,
    "languagesDescription"                => languages_description,
    "equipmentDescription"                => equipment_description,
    "featureName"                         => feature_name,
    "featureDescription"                  => feature_description,
    "avatarUrl"                           => avatar_url,
    "largeAvatarUrl"                      => large_avatar_url,
    "suggestedCharacteristicsDescription" => suggested_characteristics_description,
    "suggestedProficiencies"              => suggested_proficiencies,
    "suggestedLanguages"                  => suggested_languages,
    "organization"                        => organization&.to_dynamic,
    "contractsDescription"                => contracts_description,
    "spellsPreDescription"                => spells_pre_description,
    "spellsPostDescription"               => spells_post_description,
    "personalityTraits"                   => personality_traits.map { |x| x.to_dynamic },
    "ideals"                              => ideals.map { |x| x.to_dynamic },
    "bonds"                               => bonds.map { |x| x.to_dynamic },
    "flaws"                               => flaws.map { |x| x.to_dynamic },
    "isHomebrew"                          => is_homebrew,
    "sources"                             => sources.map { |x| x.to_dynamic },
    "spellListIds"                        => spell_list_ids,
    "featList"                            => feat_list&.to_dynamic,
  }
end

#to_json(options = nil) ⇒ Object



642
643
644
# File 'lib/ddb_ruby/fifth_edition/structs.rb', line 642

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