rb/lib/twitter-text/extractor.rb
# Extracts a list of all usernames or lists mentioned in the Tweet <tt>text</tt>
# along with the indices for where the mention ocurred.  If the
# <tt>text</tt> is nil or contains no username or list mentions, an empty array
# will be returned.
#
# If a block is given, then it will be called with each username, list slug, the start
# index, and the end index in the <tt>text</tt>. The list_slug will be an empty stirng
# if this is a username mention.
Extracts a list of all usernames or lists mentioned in the Tweet text
along with the indices for where the mention ocurred.  If the
text is nil or contains no username or list mentions, an empty array
will be returned.

If a block is given, then it will be called with each username, list slug, the start
index, and the end index in the text. The list_slug will be an empty stirng
if this is a username mention.
Extracts a list of all usernames or lists mentioned in the Tweet text along with the indices for where the mention ocurred . If the text is nil or contains no username or list mentions an empty array will be returned . If a block is given then it will be called with each username list slug the start index and the end index in the text . The list_slug will be an empty stirng if this is a username mention .
def extract_mentions_or_lists_with_indices(text) 
        return [] unless text =~ /[@＠]/
        possible_entries = []
        text.to_s.scan(Twitter::TwitterText::Regex[:valid_mention_or_list]) do |before, at, screen_name, list_slug|
          match_data = $~
                        after = $'
          unless after =~ Twitter::TwitterText::Regex[:end_mention_match]
            start_position = match_data.char_begin(3) - 1
            end_position = match_data.char_end(list_slug.nil? ? 3 : 4)
            possible_entries << {
              :screen_name => screen_name,
              :list_slug => list_slug || "",
              :indices => [start_position, end_position]
            }
          end
        end
        if block_given?
          possible_entries.each do |mention|
            yield mention[:screen_name], mention[:list_slug], mention[:indices].first, mention[:indices].last
          end
        end
        possible_entries
      end
def extract_mentions_or_lists_with_indices ( text ) return [ ] unless text =~ / [@＠]/ possible_entries = [ ] text . to_s . scan ( Twitter :: TwitterText :: Regex [ :valid_mention_or_list ] ) do | before , at , screen_name , list_slug | match_data = $~ after = $' unless after =~ Twitter :: TwitterText :: Regex [ :end_mention_match ] start_position = match_data . char_begin ( 3 ) - 1 end_position = match_data . char_end ( list_slug . nil? ? 3 : 4 ) possible_entries << { :screen_name => screen_name , :list_slug => list_slug || "" , :indices => [ start_position , end_position ] } end end if block_given? possible_entries . each do | mention | yield mention [ :screen_name ] , mention [ :list_slug ] , mention [ :indices ] . first , mention [ :indices ] . last end end possible_entries end
Extracts a list of all usernames or lists mentioned in the Tweet <tt>text</tt>
along with the indices for where the mention ocurred.
Extracts a list of all usernames or lists mentioned in the Tweet <tt > text< / tt > along with the indices for where the mention ocurred .
# :yields: username, list_slug, start, end
text
<not_specific>