2024-06-30 07:46:38 +00:00
|
|
|
# frozen_string_literaL: true
|
|
|
|
|
|
|
|
class TemplateBuilder
|
|
|
|
class << self
|
|
|
|
def create!(name:, from:, game_system:)
|
2024-07-02 17:07:06 +00:00
|
|
|
Template.create(
|
2024-06-30 07:46:38 +00:00
|
|
|
name:,
|
|
|
|
klass: from.class.name,
|
|
|
|
game_system:,
|
|
|
|
content: serialize_character_sheet_section(from),
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def serialize_character_sheet_section(section)
|
|
|
|
always_except = [ :id, :created_at, :updated_at ]
|
|
|
|
subsection_except = [ :character_id, :parent_section_id ]
|
|
|
|
always_include = {
|
|
|
|
stats: { except: always_except + [ :value ] },
|
|
|
|
text_fields: { except: always_except },
|
|
|
|
}
|
|
|
|
|
|
|
|
section.to_json(
|
|
|
|
except: always_except + subsection_except,
|
|
|
|
include: {
|
|
|
|
character_sheet_subsections: {
|
|
|
|
except: always_except + subsection_except,
|
|
|
|
include: always_include.merge(
|
|
|
|
character_sheet_subsections: {
|
|
|
|
except: always_except + subsection_except,
|
|
|
|
include: always_include,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
},
|
|
|
|
}.merge(always_include),
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|