class Ragol::Matcher
Attributes
elements[R]
Public Class Methods
new(tags)
click to toggle source
# File lib/ragol/matcher.rb, line 12 def initialize tags @elements = [ tags ].flatten.compact end
Public Instance Methods
find_match(opt)
click to toggle source
# File lib/ragol/matcher.rb, line 16 def find_match opt tag = opt.split('=', 2)[0] || opt @elements.each do |elmt| if elmt.kind_of?(Regexp) if md = elmt.match(tag) return [ :regexp, md ] end elsif tag.length > elmt.length next elsif elmt.index(tag) == 0 score = tag.length == elmt.length ? 1.0 : tag.length * 0.01 return [ :string, score ] end end nil end
match?(opt)
click to toggle source
# File lib/ragol/matcher.rb, line 34 def match? opt type, val = find_match(opt) type && val end
score(opt)
click to toggle source
# File lib/ragol/matcher.rb, line 39 def score opt type, val = find_match(opt) type && (type == :regexp ? 1.0 : val) end
to_s()
click to toggle source
# File lib/ragol/matcher.rb, line 44 def to_s @elements.join(', ') end