Class: RailsAiBridge::Serializers::Formatters::Sections::SectionFormatter

Inherits:
Base
  • Object
show all
Defined in:
lib/rails_ai_bridge/serializers/formatters/sections/section_formatter.rb

Overview

Template-method base for section formatters that follow the standard guard pattern: extract data by key, return nil when absent or errored, then delegate to #render.

Subclasses declare their context key with section and implement render(data):

class SchemaFormatter < Formatters::Sections::SectionFormatter
section :schema

private

def render(data)
  # build and return markdown string, or nil
end
end

See Also:

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.section_keySymbol (readonly)

Returns the context key this formatter reads from.

Returns:

  • (Symbol)

    the context key this formatter reads from



27
28
29
# File 'lib/rails_ai_bridge/serializers/formatters/sections/section_formatter.rb', line 27

def section_key
  @section_key
end

Instance Method Details

#callString?

Extracts data from context[section_key], applies standard guards, and delegates to #render.

Returns:

  • (String, nil)


43
44
45
46
47
48
49
# File 'lib/rails_ai_bridge/serializers/formatters/sections/section_formatter.rb', line 43

def call
  data = context[self.class.section_key]
  return unless data
  return if data[:error]

  render(data)
end