class ClientPages::Matcher

Attributes

line[RW]
tag[RW]

Public Class Methods

new(tag, line) click to toggle source
# File lib/client_pages/matcher.rb, line 5
def initialize(tag, line)
  @tag, @line = tag, line
end

Public Instance Methods

find(type) { |match| ... } click to toggle source
# File lib/client_pages/matcher.rb, line 25
def find(type)
  if block_given? && includes?(tag_pattern[type])
    line.gsub(tag_pattern[type]) { |match| yield match }
  else
    line
  end
end
includes?(pattern) click to toggle source
# File lib/client_pages/matcher.rb, line 21
def includes?(pattern)
  !!line.match(pattern)
end
match?(attribute, match) click to toggle source
# File lib/client_pages/matcher.rb, line 9
def match?(attribute, match)
  !!line.match(/<#{tag}[^>]*#{attribute}="#{match}"/i)
end
match_all?(attributes) click to toggle source
# File lib/client_pages/matcher.rb, line 13
def match_all?(attributes)
  attributes.keys.all? { |key| match?(key, attributes[key]) }
end
match_any?(attribute, match) click to toggle source
# File lib/client_pages/matcher.rb, line 17
def match_any?(attribute, match)
  !!line.match(/#{attribute}="#{match}"/i)
end

Private Instance Methods

tag_pattern() click to toggle source
# File lib/client_pages/matcher.rb, line 35
def tag_pattern
  { open: /<#{tag}[^>]*>/, close: /<\/#{tag}[^>]*>/ }
end