lib/quesadilla/extractor.rb in quesadilla-0.1.0 vs lib/quesadilla/extractor.rb in quesadilla-0.1.1
- old
+ new
@@ -9,10 +9,11 @@
include Autolinks
include Emoji
include Hashtags
include HTML
include Markdown
+ include Users
# @return [Hash] default extractor options
def self.default_options
{
markdown: true,
@@ -23,10 +24,12 @@
markdown_emphasis: true,
markdown_strikethrough: true,
hashtags: true,
autolinks: true,
emoji: true,
+ users: false,
+ user_validator: nil,
html: true,
html_renderer: Quesadilla::HTMLRenderer
}
end
@@ -39,10 +42,12 @@
# @option options markdown_emphasis [Boolean] Should extract Markdown emphasis (italic). Defaults to `true`.
# @option options markdown_strikethrough [Boolean] Should extract Markdown strikethrough. Defaults to `true`.
# @option options hashtags [Boolean] Should extract hashtags. Defaults to `true`.
# @option options autolinks [Boolean] Should automatically detect links. Defaults to `true`.
# @option options emoji [Boolean] Should extract named emoji. Defaults to `true`.
+ # @option options users [Boolean] Should extract user mentions. Defaults to `false`.
+ # @option options user_validator A callable object to validate a username. This should return the user ID of the user or nil if it is invalid. Invalid users will be left as plain text. If the validator is nil, all usernames will be extracted. Defaults to `nil`.
# @option options html [Boolean] Should generate HTML. Defaults to `true`.
# @option options html_renderer [Class] class to use as HTML renderer. Defaults to `Quesadilla::HTMLRenderer`.
def initialize(options = {})
@options = self.class.default_options.merge(options)
@renderer = @options[:html_renderer].new if @options[:html]
@@ -62,9 +67,10 @@
# Get entities
extract_markdown if @options[:markdown]
extract_hashtags if @options[:hashtags]
extract_autolinks if @options[:autolinks]
+ extract_users if @options[:users]
# Sort entities
@entities.sort! do |a, b|
a[:indices].first <=> b[:indices].first
end