Module: ThingsMcp::Formatters

Extended by:
Formatters
Included in:
Formatters
Defined in:
lib/things_mcp/formatters.rb

Overview

Output formatters for Things 3 data

This module provides formatting methods to convert raw database records into human-readable text for MCP responses.

Instance Method Summary collapse

Instance Method Details

#format_area(area) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/things_mcp/formatters.rb', line 117

def format_area(area)
  lines = []

  lines << "🏷️ **#{area[:title]}** (Area)"
  lines << "   UUID: #{area[:uuid]}" if area[:uuid]

  # Tags
  if area[:tags] && !area[:tags].empty?
    lines << "   Tags: #{area[:tags].join(", ")}"
  end

  # Projects within area
  if area[:projects] && !area[:projects].empty?
    lines << "   Projects:"
    area[:projects].each do |project|
      lines << "     📁 #{project[:title]}"
    end
  end

  lines.join("\n")
end

#format_project(project) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/things_mcp/formatters.rb', line 69

def format_project(project)
  lines = []

  # Status indicator
  status_icon = case project[:status]
  when "completed" then "✅"
  when "canceled" then "❌"
  else "📁"
  end

  lines << "#{status_icon} **#{project[:title]}** (Project)"
  lines << "   UUID: #{project[:uuid]}" if project[:uuid]

  # Notes
  if project[:notes] && !project[:notes].empty?
    lines << "   Notes: #{project[:notes].gsub("\n", " ")}"
  end

  # When/scheduling
  if project[:when] && project[:when] != "unknown"
    lines << "   When: #{project[:when]}"
  end

  if project[:start_date]
    lines << "   Start: #{project[:start_date]}"
  end

  if project[:deadline]
    lines << "   Deadline: #{project[:deadline]}"
  end

  # Tags
  if project[:tags] && !project[:tags].empty?
    lines << "   Tags: #{project[:tags].join(", ")}"
  end

  # Todos within project
  if project[:todos] && !project[:todos].empty?
    lines << "   Todos:"
    project[:todos].each do |todo|
      status = todo[:status] == "completed" ? "✓" : "○"
      lines << "     #{status} #{todo[:title]}"
    end
  end

  lines.join("\n")
end

#format_tag(tag) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/things_mcp/formatters.rb', line 139

def format_tag(tag)
  lines = []

  lines << "🏷️ #{tag[:title]}"

  if tag[:items] && !tag[:items].empty?
    lines << "   Items: #{tag[:items].size}"
  end

  lines.join("\n")
end

#format_todo(todo) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/things_mcp/formatters.rb', line 12

def format_todo(todo)
  lines = []

  # Status indicator
  status_icon = case todo[:status]
  when "completed" then "✅"
  when "canceled" then "❌"
  else "⭕"
  end

  lines << "#{status_icon} **#{todo[:title]}**"
  lines << "   UUID: #{todo[:uuid]}" if todo[:uuid]

  # Notes
  if todo[:notes] && !todo[:notes].empty?
    lines << "   Notes: #{todo[:notes].gsub("\n", " ")}"
  end

  # When/scheduling
  if todo[:when] && todo[:when] != "unknown"
    lines << "   When: #{todo[:when]}"
  end

  if todo[:start_date]
    lines << "   Start: #{todo[:start_date]}"
  end

  if todo[:deadline]
    lines << "   Deadline: #{todo[:deadline]}"
  end

  # Tags
  if todo[:tags] && !todo[:tags].empty?
    lines << "   Tags: #{todo[:tags].join(", ")}"
  end

  # Checklist items
  if todo[:checklist_items] && !todo[:checklist_items].empty?
    lines << "   Checklist:"
    todo[:checklist_items].each do |item|
      check = item[:completed] ? "✓" : "○"
      lines << "     #{check} #{item[:title]}"
    end
  end

  # Metadata
  if todo[:created]
    lines << "   Created: #{todo[:created]}"
  end

  if todo[:modified]
    lines << "   Modified: #{todo[:modified]}"
  end

  lines.join("\n")
end