Class: Ragol::Matchers
- Inherits:
-
Object
- Object
- Ragol::Matchers
- Includes:
- Logue::Loggable
- Defined in:
- lib/ragol/matchers.rb
Instance Attribute Summary collapse
-
#negatives ⇒ Object
readonly
Returns the value of attribute negatives.
-
#regexps ⇒ Object
readonly
Returns the value of attribute regexps.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#initialize(tags, negate, regexp) ⇒ Matchers
constructor
A new instance of Matchers.
- #match_type?(arg) ⇒ Boolean
- #name ⇒ Object
- #negative_match?(arg) ⇒ Boolean
- #regexp_match?(arg) ⇒ Boolean
- #tag_match?(arg) ⇒ Boolean
- #to_s ⇒ Object
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 , negate, regexp @tags = @negatives = negate @regexps = regexp end |
Instance Attribute Details
#negatives ⇒ Object (readonly)
Returns the value of attribute negatives.
12 13 14 |
# File 'lib/ragol/matchers.rb', line 12 def negatives @negatives end |
#regexps ⇒ Object (readonly)
Returns the value of attribute regexps.
13 14 15 |
# File 'lib/ragol/matchers.rb', line 13 def regexps @regexps end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
11 12 13 |
# File 'lib/ragol/matchers.rb', line 11 def @tags end |
Instance Method Details
#match_type?(arg) ⇒ 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 |
#name ⇒ Object
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
25 26 27 |
# File 'lib/ragol/matchers.rb', line 25 def negative_match? arg @negatives and @negatives.match? arg end |
#regexp_match?(arg) ⇒ 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
21 22 23 |
# File 'lib/ragol/matchers.rb', line 21 def tag_match? arg @tags and @tags.match? arg end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/ragol/matchers.rb', line 60 def to_s [ @tags, @regexps ].compact.collect { |x| x.to_s }.join(' ') end |