Class: Ragol::Matchers

Inherits:
Object
  • Object
show all
Includes:
Logue::Loggable
Defined in:
lib/ragol/matchers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags, negate, regexp) ⇒ Matchers

Returns a new instance of Matchers.



15
16
17
18
19
# File 'lib/ragol/matchers.rb', line 15

def initialize tags, negate, regexp
  @tags = tags
  @negatives = negate
  @regexps = regexp
end

Instance Attribute Details

#negativesObject (readonly)

Returns the value of attribute negatives.



12
13
14
# File 'lib/ragol/matchers.rb', line 12

def negatives
  @negatives
end

#regexpsObject (readonly)

Returns the value of attribute regexps.



13
14
15
# File 'lib/ragol/matchers.rb', line 13

def regexps
  @regexps
end

#tagsObject (readonly)

Returns the value of attribute tags.



11
12
13
# File 'lib/ragol/matchers.rb', line 11

def tags
  @tags
end

Instance Method Details

#match_type?(arg) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ragol/matchers.rb', line 33

def match_type? arg
  case 
  when tm = tag_match?(arg)
    [ :tag_match, tm ]
  when nm = negative_match?(arg)
    [ :negative_match, nm ]
  when rm = regexp_match?(arg)
    [ :regexp_match, rm ]
  else
    nil
  end
end

#nameObject



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ragol/matchers.rb', line 46

def name
  @name ||= begin
              if @tags
                if longtag = @tags.elements.find { |t| t[0, 2] == '--' }
                  longtag.sub(%r{^--}, '')
                else
                  @tags.elements[0][1 .. -1]
                end
              elsif @regexps
                @regexps.elements[0].to_s
              end
            end
end

#negative_match?(arg) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/ragol/matchers.rb', line 25

def negative_match? arg
  @negatives and @negatives.match? arg
end

#regexp_match?(arg) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/ragol/matchers.rb', line 29

def regexp_match? arg
  @regexps and @regexps.match? arg
end

#tag_match?(arg) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ragol/matchers.rb', line 21

def tag_match? arg
  @tags and @tags.match? arg
end

#to_sObject



60
61
62
# File 'lib/ragol/matchers.rb', line 60

def to_s
  [ @tags, @regexps ].compact.collect { |x| x.to_s }.join(' ')
end