class SelectedLinks::Link
Attributes
html_options[R]
name[R]
options[R]
source[RW]
Public Class Methods
new(*args, &block)
click to toggle source
# File lib/selected_links/link.rb, line 6 def initialize(*args, &block) @name, @options, @html_options = parse_args(block_given?, *args) @matcher = @html_options.delete(:matcher) @source = @html_options.delete(:source) @class_name = @html_options.delete(:class_name) end
Public Instance Methods
generate()
click to toggle source
# File lib/selected_links/link.rb, line 13 def generate merge_classes if is_match? self end
Private Instance Methods
is_match?()
click to toggle source
# File lib/selected_links/link.rb, line 33 def is_match? # Always return true if the source and the matcher match. return true if url_match?(@source, @matcher) # If not check for fallback and presence of @matcher and check again if necessary. if (@matcher && SelectedLinks.fallback_to_name) || !@matcher return url_match?(@source, @name) else return false end end
merge_classes()
click to toggle source
# File lib/selected_links/link.rb, line 28 def merge_classes name = @class_name || SelectedLinks.default_class_name @html_options.merge!({class: name}) { |key, old_v, new_v| [old_v, new_v].join(' ') } end
parse_args(block, *args)
click to toggle source
# File lib/selected_links/link.rb, line 20 def parse_args(block, *args) if block [nil, args.first, args.second || {}] else [args[0], args[1], args[2] || {}] end end
url_match?(source, matcher)
click to toggle source
# File lib/selected_links/link.rb, line 44 def url_match?(source, matcher) return false unless matcher # nil.to_s returns "" source =~ /#{matcher}/i end