Class: Collavre::Tools::CreativeRetrievalService

Inherits:
Object
  • Object
show all
Extended by:
T::Sig, ToolMeta
Defined in:
app/services/collavre/tools/creative_retrieval_service.rb

Instance Method Summary collapse

Instance Method Details

#call(id: nil, query: nil, level: 3, tags: nil, progress_min: nil, progress_max: nil, updated_since: nil, include_comments: false, format: "markdown") ⇒ Object



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
# File 'app/services/collavre/tools/creative_retrieval_service.rb', line 35

def call(id: nil, query: nil, level: 3, tags: nil, progress_min: nil, progress_max: nil, updated_since: nil, include_comments: false, format: "markdown")
  level ||= 3
  format ||= "markdown"
  include_comments ||= false

  raise "Current.user is required" unless Current.user

  creatives = fetch_creatives(id: id, query: query)
  creatives = apply_filters(creatives, tags: tags, progress_min: progress_min, progress_max: progress_max, updated_since: updated_since)

  # Search queries return a flat list — no subtree expansion needed
  if query.present? && id.blank?
    creatives.map do |c|
      { id: c.id, description: Creatives::TreeFormatter.plain_description(c), progress: c.progress.to_f.round(2) }
    end
  elsif format == "json"
    build_json_tree(creatives, depth: level, include_comments: include_comments)
  else
    formatter = Creatives::TreeFormatter.new(
      max_depth: level - 1,
      include_header: true,
      include_comments: include_comments
    )
    formatter.format(creatives) + "\n"
  end
end