Class: Anchor::Region
- Inherits:
-
Object
- Object
- Anchor::Region
- Defined in:
- lib/anchor/region.rb
Instance Method Summary collapse
- #fence(content) ⇒ Object
-
#initialize(start_marker:, end_marker:) ⇒ Region
constructor
A new instance of Region.
- #present?(text) ⇒ Boolean
- #regex ⇒ Object
- #replace(text:, content:) ⇒ Object
Constructor Details
#initialize(start_marker:, end_marker:) ⇒ Region
Returns a new instance of Region.
3 4 5 6 |
# File 'lib/anchor/region.rb', line 3 def initialize(start_marker:, end_marker:) @start_marker = start_marker @end_marker = end_marker end |
Instance Method Details
#fence(content) ⇒ Object
10 |
# File 'lib/anchor/region.rb', line 10 def fence(content) = [@start_marker, content, @end_marker].join("\n") |
#present?(text) ⇒ Boolean
8 |
# File 'lib/anchor/region.rb', line 8 def present?(text) = text.match?(regex) |
#regex ⇒ Object
12 |
# File 'lib/anchor/region.rb', line 12 def regex = /#{Regexp.escape(@start_marker)}(.*?)#{Regexp.escape(@end_marker)}/m |
#replace(text:, content:) ⇒ Object
9 |
# File 'lib/anchor/region.rb', line 9 def replace(text:, content:) = text.gsub(regex) { content[regex] } |