Sha256: a90e247cbdf6ac8cad257ecccb6c788099cf8034a1651d837a48940097080edb

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

# encoding: UTF-8

module Quesadilla
  class Extractor
    # Extract hashtags.
    #
    # This module has no public methods.
    module Hashtags
    private

      require 'twitter-text'

      def extract_hashtags
        Twitter::Extractor::extract_hashtags_with_indices(@working_text).each do |entity|
          hashtag = entity[:hashtag]

          # Validate
          if validator = @options[:hashtag_validator]
            next unless validator.call(hashtag)
          end

          display_text = "##{hashtag}"
          @entities << {
            type: ENTITY_TYPE_HASHTAG,
            text: display_text,
            display_text: display_text,
            indices: entity[:indices],
            hashtag: hashtag.downcase
          }
          @working_text.sub!(display_text, REPLACE_TOKEN * display_text.length)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
quesadilla-0.1.3 lib/quesadilla/extractor/hashtags.rb
quesadilla-0.1.2 lib/quesadilla/extractor/hashtags.rb