Class: Lab42::Match
- Inherits:
-
Object
- Object
- Lab42::Match
- Defined in:
- lib/lab42/match.rb,
lib/lab42/match/version.rb
Constant Summary collapse
- AmbigousArgAndBlock =
Class.new RuntimeError
- NotMatchedYet =
Class.new RuntimeError
- UnsuccessfulMerge =
Class.new RuntimeError
- Parts =
{ first: 0, first_capture: 2, first_match: 1, last: -1, last_capture: -3, last_match: -2, post: -1, pre: 0, prefix: 0, suffix: -1 }
- VERSION =
"0.1.2"
Instance Attribute Summary collapse
-
#rgx ⇒ Object
readonly
Returns the value of attribute rgx.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #[](capt_index) ⇒ Object
- #capts ⇒ Object
- #groups ⇒ Object
- #match(with = nil) ⇒ Object
- #matched? ⇒ Boolean
- #parts ⇒ Object
- #replace(cpt_index, with = nil, &blk) ⇒ Object
- #replace_part(part_index, with = nil, &blk) ⇒ Object
- #string ⇒ Object
- #success? ⇒ Boolean
Instance Attribute Details
#rgx ⇒ Object (readonly)
Returns the value of attribute rgx.
20 21 22 |
# File 'lib/lab42/match.rb', line 20 def rgx @rgx end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
20 21 22 |
# File 'lib/lab42/match.rb', line 20 def subject @subject end |
Instance Method Details
#[](capt_index) ⇒ Object
23 24 25 |
# File 'lib/lab42/match.rb', line 23 def [](capt_index) match&.[](capt_index) end |
#capts ⇒ Object
27 28 29 30 31 |
# File 'lib/lab42/match.rb', line 27 def capts _assure_matched? match && @par match&.captures end |
#groups ⇒ Object
33 34 35 36 |
# File 'lib/lab42/match.rb', line 33 def groups _assure_success @groups end |
#match(with = nil) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/lab42/match.rb', line 38 def match(with=nil) if with return _match(with) end _assure_matched? @match end |
#matched? ⇒ Boolean
46 47 48 |
# File 'lib/lab42/match.rb', line 46 def matched? @matched end |
#parts ⇒ Object
50 51 52 53 |
# File 'lib/lab42/match.rb', line 50 def parts _assure_success @parts end |
#replace(cpt_index, with = nil, &blk) ⇒ Object
55 56 57 58 59 |
# File 'lib/lab42/match.rb', line 55 def replace(cpt_index, with=nil, &blk) _assure_success _assure_unambigous_args(with, blk) _replace_part(2 * cpt_index, with, &blk) end |
#replace_part(part_index, with = nil, &blk) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lab42/match.rb', line 61 def replace_part(part_index, with=nil, &blk) _assure_success _assure_unambigous_args(with, blk) case part_index when Symbol idx = Parts.fetch(part_index){ raise IllegalSymbolicPartIndex, "#{part_index} is not one of the predefined symbolic indices, which are #{Parts.keys.map(&:inspect).join(", ")}" } _replace_part(idx, with, &blk) else _replace_part(part_index, with, &blk) end end |
#string ⇒ Object
73 74 75 76 |
# File 'lib/lab42/match.rb', line 73 def string _assure_success @string end |
#success? ⇒ Boolean
78 79 80 |
# File 'lib/lab42/match.rb', line 78 def success? !!@match end |