Class: Slk::Formatters::MessageFormatter
- Inherits:
-
Object
- Object
- Slk::Formatters::MessageFormatter
- Defined in:
- lib/slk/formatters/message_formatter.rb
Overview
Formats Slack messages for terminal display or JSON output rubocop:disable Metrics/ClassLength
Instance Method Summary collapse
-
#build_reaction_formatter(output, emoji_replacer, cache_store) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #format(message, workspace:, options: {}) ⇒ Object
- #format_json(message, workspace: nil, options: {}) ⇒ Object
- #format_reaction_inline(message, options) ⇒ Object
- #format_simple(message, workspace:, options: {}) ⇒ Object
-
#initialize(output:, mention_replacer:, emoji_replacer:, cache_store:, api_client: nil, text_processor: nil, on_debug: nil) ⇒ MessageFormatter
constructor
rubocop:disable Metrics/ParameterLists.
Constructor Details
#initialize(output:, mention_replacer:, emoji_replacer:, cache_store:, api_client: nil, text_processor: nil, on_debug: nil) ⇒ MessageFormatter
rubocop:disable Metrics/ParameterLists
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/slk/formatters/message_formatter.rb', line 9 def initialize(output:, mention_replacer:, emoji_replacer:, cache_store:, api_client: nil, text_processor: nil, on_debug: nil) @output = output @cache = cache_store @api_client = api_client @on_debug = on_debug @text_processor = text_processor || TextProcessor.new( mention_replacer: mention_replacer, emoji_replacer: emoji_replacer ) @reaction_formatter = build_reaction_formatter(output, emoji_replacer, cache_store) @json_formatter = JsonMessageFormatter.new(cache_store: cache_store) end |
Instance Method Details
#build_reaction_formatter(output, emoji_replacer, cache_store) ⇒ Object
rubocop:enable Metrics/ParameterLists
24 25 26 |
# File 'lib/slk/formatters/message_formatter.rb', line 24 def build_reaction_formatter(output, emoji_replacer, cache_store) ReactionFormatter.new(output: output, emoji_replacer: emoji_replacer, cache_store: cache_store) end |
#format(message, workspace:, options: {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/slk/formatters/message_formatter.rb', line 28 def format(, workspace:, options: {}) username = resolve_username(, workspace, ) = (.) text = @text_processor.process(.text, workspace, ) header = build_header(, username) display_text = build_display_text(text, , header, ) main_line = "#{header} #{display_text}" build_output_lines(main_line, , workspace, , display_text) end |
#format_json(message, workspace: nil, options: {}) ⇒ Object
57 58 59 |
# File 'lib/slk/formatters/message_formatter.rb', line 57 def format_json(, workspace: nil, options: {}) @json_formatter.format(, workspace: workspace, options: ) end |
#format_reaction_inline(message, options) ⇒ Object
53 54 55 |
# File 'lib/slk/formatters/message_formatter.rb', line 53 def format_reaction_inline(, ) @reaction_formatter.format_inline(.reactions, ) end |
#format_simple(message, workspace:, options: {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/slk/formatters/message_formatter.rb', line 40 def format_simple(, workspace:, options: {}) username = resolve_username(, workspace, ) = (.) text = @text_processor.process(.text, workspace, ) reaction_text = '' unless [:no_reactions] || .reactions.empty? reaction_text = format_reaction_inline(, ) end "#{@output.blue("[#{}]")} #{@output.bold(username)}: #{text}#{reaction_text}" end |