Class: Slk::Formatters::TextProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/formatters/text_processor.rb

Overview

Centralized text processing for message display Handles HTML entity decoding, mention replacement, and emoji replacement

Instance Method Summary collapse

Constructor Details

#initialize(mention_replacer:, emoji_replacer:) ⇒ TextProcessor

Returns a new instance of TextProcessor.



8
9
10
11
# File 'lib/slk/formatters/text_processor.rb', line 8

def initialize(mention_replacer:, emoji_replacer:)
  @mentions = mention_replacer
  @emoji = emoji_replacer
end

Instance Method Details

#process(text, workspace, options = {}) ⇒ String

Process raw Slack message text for display

Parameters:

  • text (String)

    Raw message text from Slack API

  • workspace (Models::Workspace)

    The workspace for name resolution

  • options (Hash) (defaults to: {})

    Processing options

Options Hash (options):

  • :no_emoji (Boolean)

    Skip emoji replacement

  • :no_mentions (Boolean)

    Skip mention replacement

Returns:

  • (String)

    Processed text ready for display



20
21
22
23
24
25
26
27
# File 'lib/slk/formatters/text_processor.rb', line 20

def process(text, workspace, options = {})
  return '[No text]' if text.to_s.empty?

  result = decode_html_entities(text.dup)
  result = safe_replace_mentions(result, workspace) unless options[:no_mentions]
  result = safe_replace_emoji(result, workspace) unless options[:no_emoji]
  result
end