Class: HotwireClub::MCP::Chunk

Inherits:
Data
  • Object
show all
Defined in:
lib/hotwire_club/mcp/chunk.rb

Overview

Data class representing a single chunk of a document

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category

Returns:

  • (Object)

    the current value of category



6
7
8
# File 'lib/hotwire_club/mcp/chunk.rb', line 6

def category
  @category
end

#doc_idObject (readonly)

Returns the value of attribute doc_id

Returns:

  • (Object)

    the current value of doc_id



6
7
8
# File 'lib/hotwire_club/mcp/chunk.rb', line 6

def doc_id
  @doc_id
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



6
7
8
# File 'lib/hotwire_club/mcp/chunk.rb', line 6

def id
  @id
end

#positionObject (readonly)

Returns the value of attribute position

Returns:

  • (Object)

    the current value of position



6
7
8
# File 'lib/hotwire_club/mcp/chunk.rb', line 6

def position
  @position
end

#tagsObject (readonly)

Returns the value of attribute tags

Returns:

  • (Object)

    the current value of tags



6
7
8
# File 'lib/hotwire_club/mcp/chunk.rb', line 6

def tags
  @tags
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



6
7
8
# File 'lib/hotwire_club/mcp/chunk.rb', line 6

def text
  @text
end

#titleObject (readonly)

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



6
7
8
# File 'lib/hotwire_club/mcp/chunk.rb', line 6

def title
  @title
end

Class Method Details

.build_chunk_id(doc_id, section_idx, part_idx) ⇒ String

Build chunk ID from document ID, section index, and part index

Parameters:

  • doc_id (String)

    Document ID

  • section_idx (Integer)

    Section index

  • part_idx (Integer)

    Part index

Returns:

  • (String)

    Chunk ID



36
37
38
39
40
41
42
# File 'lib/hotwire_club/mcp/chunk.rb', line 36

def self.build_chunk_id(doc_id, section_idx, part_idx)
  if part_idx.zero?
    "#{doc_id}#s#{section_idx}"
  else
    "#{doc_id}#s#{section_idx}-#{part_idx}"
  end
end

.create_from_section(doc:, section_idx:, part_idx:, section_title:, text:, position:) ⇒ Chunk

Create a chunk from a document section

Parameters:

  • doc (Doc)

    The document this chunk belongs to

  • section_idx (Integer)

    The index of the section within the document

  • part_idx (Integer)

    The index of the part within the section (0 for first part)

  • section_title (String, nil)

    The title of the section

  • text (String)

    The text content of the chunk

  • position (Integer)

    The position of the chunk within the document

Returns:

  • (Chunk)

    A new Chunk instance with generated ID



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hotwire_club/mcp/chunk.rb', line 16

def self.create_from_section(doc:, section_idx:, part_idx:, section_title:, text:, position:)
  chunk_id = build_chunk_id(doc.id, section_idx, part_idx)

  new(
    id:       chunk_id,
    doc_id:   doc.id,
    title:    section_title,
    category: doc.category,
    tags:     doc.tags,
    position: position,
    text:     text,
  )
end