Class: Afterlife::Clickup::GetIdsFromText

Inherits:
Object
  • Object
show all
Defined in:
lib/afterlife/clickup/get_ids_from_text.rb

Constant Summary collapse

ID_PATTERNS =
[
  /#CU-([a-z0-9]+)/i,
  /#CU_([a-z0-9]+)/i,
  /#([a-z0-9]{8,})/i,
  /CU-([a-z0-9]+)/i,
].freeze

Class Method Summary collapse

Class Method Details

.call(text, convert_to_link = false) ⇒ Object

rubocop:disable Metrics/MethodLength



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/afterlife/clickup/get_ids_from_text.rb', line 13

def self.call(text, convert_to_link = false) # rubocop:disable Metrics/MethodLength
  ids = Set.new

  ID_PATTERNS.each do |pattern|
    text.scan(pattern) do |match|
      ids.add(match.first.downcase)
    end
  end

  if convert_to_link
    ids.map { |id| "https://app.clickup.com/t/#{id}" }
  else
    ids.to_a
  end
end