Class: Ace::Idea::Molecules::IdeaClipboardReader

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/idea/molecules/idea_clipboard_reader.rb

Overview

Reads content from the system clipboard for idea capture. Supports: plain text, RTF, HTML (as text), images (as attachments).

Constant Summary collapse

MAX_CONTENT_SIZE =

100KB

100 * 1024

Class Method Summary collapse

Class Method Details

.macos?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ace/idea/molecules/idea_clipboard_reader.rb', line 39

def self.macos?
  RUBY_PLATFORM.include?("darwin")
end

.macos_clipboard_available?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ace/idea/molecules/idea_clipboard_reader.rb', line 43

def self.macos_clipboard_available?
  defined?(Ace::Support::MacClipboard)
end

.readHash

Read clipboard content

Returns:

  • (Hash)

    Result with :success, :content, :type, :attachments keys



29
30
31
32
33
34
35
# File 'lib/ace/idea/molecules/idea_clipboard_reader.rb', line 29

def self.read
  if macos? && macos_clipboard_available?
    read_macos
  else
    read_generic
  end
end

.read_genericObject



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
# File 'lib/ace/idea/molecules/idea_clipboard_reader.rb', line 69

def self.read_generic
  unless defined?(Clipboard)
    return {
      success: false,
      error: "Clipboard gem not available. Install 'clipboard' gem for clipboard support."
    }
  end

  content = Clipboard.paste

  if content.nil? || content.strip.empty?
    return {
      success: false,
      error: "Clipboard is empty. Provide text argument or copy content to clipboard."
    }
  end

  if content.bytesize > MAX_CONTENT_SIZE
    return {
      success: false,
      error: "Clipboard content too large (#{content.bytesize} bytes, max #{MAX_CONTENT_SIZE} bytes)"
    }
  end

  if content.encoding == Encoding::ASCII_8BIT || content.include?("\x00")
    return {
      success: false,
      error: "Clipboard contains binary data. Only text content is supported."
    }
  end

  {
    success: true,
    platform: :generic,
    type: :text,
    content: content,
    attachments: [],
    files: []
  }
rescue => e
  {
    success: false,
    error: "Unable to read clipboard: #{e.message}"
  }
end

.read_macosObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ace/idea/molecules/idea_clipboard_reader.rb', line 47

def self.read_macos
  raw = Ace::Support::MacClipboard::Reader.read
  return {success: false, error: raw[:error]} unless raw[:success]

  parsed = Ace::Support::MacClipboard::ContentParser.parse(raw)

  has_attachments = parsed[:attachments].any?
  type = has_attachments ? :rich : :text
  file_attachments = parsed[:attachments].select { |a| a[:type] == :file }

  {
    success: true,
    platform: :macos,
    type: type,
    content: parsed[:text],
    attachments: parsed[:attachments],
    files: file_attachments.map { |a| a[:source_path] }
  }
rescue
  read_generic
end