Class: Aidp::PromptOptimization::Fragment
- Inherits:
-
Object
- Object
- Aidp::PromptOptimization::Fragment
- Defined in:
- lib/aidp/prompt_optimization/style_guide_indexer.rb
Overview
Represents a fragment of the style guide
Each fragment corresponds to a section or subsection and can be independently selected for inclusion in prompts
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#heading ⇒ Object
readonly
Returns the value of attribute heading.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#estimated_tokens ⇒ Integer
Estimate token count (rough approximation: 1 token ≈ 4 chars).
-
#initialize(id:, heading:, level:, content:, tags: []) ⇒ Fragment
constructor
A new instance of Fragment.
- #inspect ⇒ Object
-
#matches_any_tag?(query_tags) ⇒ Boolean
Check if fragment matches any of the given tags.
-
#size ⇒ Integer
Get the size of the fragment in characters.
-
#summary ⇒ Hash
Get a summary of the fragment.
- #to_s ⇒ Object
Constructor Details
#initialize(id:, heading:, level:, content:, tags: []) ⇒ Fragment
Returns a new instance of Fragment.
188 189 190 191 192 193 194 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 188 def initialize(id:, heading:, level:, content:, tags: []) @id = id @heading = heading @level = level @content = content @tags = end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
186 187 188 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 186 def content @content end |
#heading ⇒ Object (readonly)
Returns the value of attribute heading.
186 187 188 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 186 def heading @heading end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
186 187 188 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 186 def id @id end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
186 187 188 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 186 def level @level end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
186 187 188 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 186 def @tags end |
Instance Method Details
#estimated_tokens ⇒ Integer
Estimate token count (rough approximation: 1 token ≈ 4 chars)
215 216 217 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 215 def estimated_tokens (size / 4.0).ceil end |
#inspect ⇒ Object
237 238 239 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 237 def inspect "#<Fragment id=#{@id} heading=\"#{@heading}\" level=#{@level} tags=#{@tags}>" end |
#matches_any_tag?(query_tags) ⇒ Boolean
Check if fragment matches any of the given tags
200 201 202 203 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 200 def matches_any_tag?() = .map(&:downcase) @tags.any? { |tag| .include?(tag.downcase) } end |
#size ⇒ Integer
Get the size of the fragment in characters
208 209 210 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 208 def size @content.length end |
#summary ⇒ Hash
Get a summary of the fragment
222 223 224 225 226 227 228 229 230 231 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 222 def summary { id: @id, heading: @heading, level: @level, tags: @tags, size: size, estimated_tokens: estimated_tokens } end |
#to_s ⇒ Object
233 234 235 |
# File 'lib/aidp/prompt_optimization/style_guide_indexer.rb', line 233 def to_s "Fragment<#{@id}>" end |