summaryrefslogtreecommitdiff
path: root/qa/qa/page/element.rb
blob: 9944a39ce07e6f79d8f1ce3c457b9a12cef33e9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
module QA
  module Page
    class Element
      attr_reader :name

      def initialize(name, pattern = nil)
        @name = name
        @pattern = pattern || selector
      end

      def selector
        "qa-#{@name.to_s.tr('_', '-')}"
      end

      def selector_css
        ".#{selector}"
      end

      def expression
        if @pattern.is_a?(String)
          @_regexp ||= Regexp.new(Regexp.escape(@pattern))
        else
          @pattern
        end
      end

      def matches?(line)
        !!(line =~ expression)
      end
    end
  end
end