]>
cat aescling's git repositories - mastodon.git/blob - app/lib/extractor.rb
1 # frozen_string_literal: true
4 extend Twitter
::Extractor
8 # :yields: username, list_slug, start, end
9 def extract_mentions_or_lists_with_indices(text
)
10 return [] unless text
=~ Twitter
::Regex[:at_signs]
14 text
.to_s
.scan(Account
::MENTION_RE) do |screen_name
, _
|
15 match_data
= $LAST_MATCH_INFO
17 unless after =~ Twitter::Regex[:end_mention_match]
18 start_position = match_data.char_begin(1) - 1
19 end_position = match_data.char_end(1)
21 screen_name: screen_name,
22 indices: [start_position, end_position],
28 possible_entries.each do |mention|
29 yield mention[:screen_name], mention[:indices].first, mention[:indices].last
35 def extract_hashtags_with_indices(text, **)
36 return [] unless text =~ /#/
39 text.scan(Tag::HASHTAG_RE) do |hash_text, _|
40 match_data = $LAST_MATCH_INFO
41 start_position = match_data.char_begin(1) - 1
42 end_position = match_data.char_end(1)
45 hash_text
.match(/(.+)(https?\Z)/) do |matched
|
46 hash_text
= matched
[1]
47 end_position
-= matched
[2].char_length
53 indices
: [start_position
, end_position
],
57 tags
.each
{ |tag
| yield tag
[:hashtag], tag
[:indices].first
, tag
[:indices].last
} if block_given
?
61 def extract_cashtags_with_indices(_text
)
62 [] # always returns empty array
This page took 0.079582 seconds and 4 git commands to generate.