Class: HotwireClub::MCP::Doc
- Inherits:
-
Data
- Object
- Data
- HotwireClub::MCP::Doc
- Defined in:
- lib/hotwire_club/mcp/doc.rb
Overview
Data class representing a single document
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#free ⇒ Object
readonly
Returns the value of attribute free.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.extract_category(front_matter) ⇒ String?
Extract category from front matter.
-
.extract_summary(front_matter, body) ⇒ String
Extract summary from front matter or body.
-
.extract_title(front_matter, file_path) ⇒ String
Extract title from front matter or filename.
- .from_file(file_path) ⇒ Object
-
.id_from_title(title) ⇒ String
Generate a stable document ID from a title.
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def body @body end |
#category ⇒ Object (readonly)
Returns the value of attribute category
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def category @category end |
#date ⇒ Object (readonly)
Returns the value of attribute date
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def date @date end |
#free ⇒ Object (readonly)
Returns the value of attribute free
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def free @free end |
#id ⇒ Object (readonly)
Returns the value of attribute id
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def id @id end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def summary @summary end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def @tags end |
#title ⇒ Object (readonly)
Returns the value of attribute title
30 31 32 |
# File 'lib/hotwire_club/mcp/doc.rb', line 30 def title @title end |
Class Method Details
.extract_category(front_matter) ⇒ String?
Extract category from front matter
89 90 91 |
# File 'lib/hotwire_club/mcp/doc.rb', line 89 def self.extract_category(front_matter) front_matter["categories"]&.first || front_matter["category"] end |
.extract_summary(front_matter, body) ⇒ String
Extract summary from front matter or body
98 99 100 |
# File 'lib/hotwire_club/mcp/doc.rb', line 98 def self.extract_summary(front_matter, body) front_matter["description"] || body.split("\n\n").first end |
.extract_title(front_matter, file_path) ⇒ String
Extract title from front matter or filename
81 82 83 |
# File 'lib/hotwire_club/mcp/doc.rb', line 81 def self.extract_title(front_matter, file_path) front_matter["title"] || File.basename(file_path, ".md") end |
.from_file(file_path) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/hotwire_club/mcp/doc.rb', line 47 def self.from_file(file_path) require "front_matter_parser" parsed = FrontMatterParser::Parser.parse_file(file_path) front_matter = parsed.front_matter # Only process files with ready: true return nil unless front_matter["ready"] == true title = extract_title(front_matter, file_path) id = id_from_title(title) category = extract_category(front_matter) = Array(front_matter["tags"]) body = parsed.content summary = extract_summary(front_matter, body) date = front_matter["date"] free = front_matter["free"] new( id: id, title: title, category: category, tags: , body: body, summary: summary, date: date, free: free, ) end |
.id_from_title(title) ⇒ String
Generate a stable document ID from a title
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hotwire_club/mcp/doc.rb', line 35 def self.id_from_title(title) return nil if title.nil? || title.empty? # Convert to lowercase, replace spaces and underscores with hyphens, # remove special characters (keep alphanumeric and hyphens), collapse multiple hyphens title.downcase .gsub(%r{[\s_]+}, "-") .gsub(%r{[^a-z0-9-]}, "") .gsub(%r{-+}, "-") .gsub(%r{^-|-$}, "") end |