Class: Anchor::Region

Inherits:
Object
  • Object
show all
Defined in:
lib/anchor/region.rb

Instance Method Summary collapse

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

Returns:

  • (Boolean)


8
# File 'lib/anchor/region.rb', line 8

def present?(text) = text.match?(regex)

#regexObject



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] }