DecodeSourceDecodeRBSWrapper

class Wrapper

Base wrapper class for RBS generation from definitions.

Definitions

def initialize(definition)

Initialize the wrapper instance variables.

Signature

parameter definition Definition

The definition to wrap.

Implementation

def initialize(definition)
	@definition = definition
	@tags = nil
end

def tags

Extract RBS tags from the definition's documentation.

Signature

returns Array<Comment::RBS>

The RBS tags found in the documentation.

Implementation

def tags
	@tags ||= extract_tags
end

def extract_tags

Extract RBS tags from the definition's documentation.

Signature

returns Array<Comment::RBS>

The RBS tags found in the documentation.

Implementation

def extract_tags
	@definition.documentation&.children&.select do |child|
		child.is_a?(Comment::RBS)
	end || []
end

def extract_comment(definition = @definition)

Extract comment from definition documentation.

Signature

parameter definition Definition

The definition to extract comment from (defaults to @definition).

returns RBS::AST::Comment, nil

The extracted comment or nil if no documentation.

Implementation

def extract_comment(definition = @definition)
	documentation = definition.documentation
	return nil unless documentation
	
	# Extract the main description text (non-tag content)
	comment_lines = []
	
	documentation.children&.each do |child|
		if child.is_a?(Decode::Comment::Text)
			comment_lines << child.line.strip
		elsif !child.is_a?(Decode::Comment::Tag)
			# Handle other text-like nodes
			comment_lines << child.to_s.strip if child.respond_to?(:to_s)
		end
	end
	
	# Join lines with newlines to preserve markdown formatting
	unless comment_lines.empty?
		comment_text = comment_lines.join("\n").strip
		return ::RBS::AST::Comment.new(string: comment_text, location: nil) unless comment_text.empty?
	end
	
	nil
end