|
|
@ -30,4 +30,30 @@ module Extractor |
|
|
|
end |
|
|
|
end |
|
|
|
possible_entries |
|
|
|
possible_entries |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_hashtags_with_indices(text, _options = {}) |
|
|
|
|
|
|
|
return [] unless text =~ /#/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags = [] |
|
|
|
|
|
|
|
text.scan(Tag::HASHTAG_RE) do |hash_text, _| |
|
|
|
|
|
|
|
match_data = $LAST_MATCH_INFO |
|
|
|
|
|
|
|
start_position = match_data.char_begin(1) - 1 |
|
|
|
|
|
|
|
end_position = match_data.char_end(1) |
|
|
|
|
|
|
|
after = $' |
|
|
|
|
|
|
|
if after =~ %r{\A://} |
|
|
|
|
|
|
|
hash_text.match(/(.+)(https?\Z)/) do |matched| |
|
|
|
|
|
|
|
hash_text = matched[1] |
|
|
|
|
|
|
|
end_position -= matched[2].char_length |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags << { |
|
|
|
|
|
|
|
hashtag: hash_text, |
|
|
|
|
|
|
|
indices: [start_position, end_position], |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags.each { |tag| yield tag[:hashtag], tag[:indices].first, tag[:indices].last } if block_given? |
|
|
|
|
|
|
|
tags |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|