Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ruby_llm/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def format
end
end

def empty?
@text.to_s.strip.empty? && @attachments.empty?
end

# For Rails serialization
def to_h
{ text: @text, attachments: @attachments.map(&:to_h) }
Expand Down
29 changes: 29 additions & 0 deletions spec/ruby_llm/content_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe RubyLLM::Content do
describe '#empty?' do
it 'is true when text is empty and there are no attachments' do
expect(described_class.new('')).to be_empty
end

it 'is true when text is whitespace-only and there are no attachments' do
expect(described_class.new(" \n\t")).to be_empty
end

it 'is false when text has content' do
expect(described_class.new('hello')).not_to be_empty
end

it 'is false when attachments are present without text' do
content = described_class.new(nil, 'spec/fixtures/ruby.txt')
expect(content).not_to be_empty
end

it 'is false when both text and attachments are present' do
content = described_class.new('hello', 'spec/fixtures/ruby.txt')
expect(content).not_to be_empty
end
end
end