Class: DeepAgents::Todo

Inherits:
Object
  • Object
show all
Defined in:
lib/deepagents/state.rb

Overview

Todo class for managing todos

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, status = "pending") ⇒ Todo

Returns a new instance of Todo.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/deepagents/state.rb', line 8

def initialize(content, status = "pending")
  raise ArgumentError, "Todo content cannot be nil or empty" if content.nil? || content.empty?
  @content = content
  @status = validate_status(status)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/deepagents/state.rb', line 6

def content
  @content
end

#statusObject

Returns the value of attribute status.



6
7
8
# File 'lib/deepagents/state.rb', line 6

def status
  @status
end

Class Method Details

.from_h(hash) ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
# File 'lib/deepagents/state.rb', line 21

def self.from_h(hash)
  content = hash[:content] || hash["content"]
  status = hash[:status] || hash["status"] || "pending"
  
  raise ArgumentError, "Todo hash must contain content" if content.nil?
  new(content, status)
end

Instance Method Details

#to_hObject



14
15
16
17
18
19
# File 'lib/deepagents/state.rb', line 14

def to_h
  {
    content: @content,
    status: @status
  }
end