class Linkificator::ConditionsStorage::Condition

Attributes

options[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 4
def initialize(options={})
  @options = options
end

Public Instance Methods

match?(options) click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 8
def match?(options)
  [
      context[:target]      ?  detect_presence(context[:target],      options[:target])  : true,
      context[:target_not]  ? !detect_presence(context[:target_not],  options[:target])  : true,
      context[:current]     ?  detect_presence(context[:current],     options[:current]) : true,
      context[:current_not] ? !detect_presence(context[:current_not], options[:current]) : true,
  ].all?
end

Private Instance Methods

context() click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 71
def context
  @context ||= options[:context] || {}
end
detect_presence(pool, element) click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 58
def detect_presence(pool, element)
  pool.detect { |target| match_regexp(element, target) }.present?
end
match_regexp(str, regexp_str) click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 62
def match_regexp(str, regexp_str)
  regexp = wrap_regexp(regexp_str)
  str.to_s.match(regexp)
end
processing() click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 75
def processing
  @processing ||= options[:processing] || {}
end
view_context(view_context=nil) click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 54
def view_context(view_context=nil)
  view_context || (@view_context ||= ViewContext.new)
end
wrap_regexp(str) click to toggle source
# File lib/linkificator/conditions_storage/condition.rb, line 67
def wrap_regexp(str)
  /^#{str}$/i
end