class Prolog::Services::ReplaceContent::Splitter::Paired

A “paired” splitter inserts an empty pair of HTML tags before the selected content, and another such empty tag pair afterwards. The tag pairs each have an ID attribute string which ends in '-begin' for the tag pair before the selection, and '-end' for the tag pair after the content. The default for the tag is the anchor tag (:a), though that may be changed by specifying a synbolic `tag` parameter (such as :span). The default text before the '-begin'/'-end' text in the ID attribute strings is 'selection'; that may similary be changed by specifying the `identifier` parameter to the initialiser.

Constants

DEFAULT_ID

Attributes

content[R]
endpoints[R]
identifier[R]
tag[R]

Public Class Methods

new(content:, endpoints:, tag: :a, identifier: DEFAULT_ID) click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 20
def initialize(content:, endpoints:, tag: :a, identifier: DEFAULT_ID)
  @content = content
  @endpoints = endpoints
  @identifier = identifier
  @tag = tag
  self
end

Public Instance Methods

inner() click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 28
def inner
  content[endpoints]
end
source() click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 32
def source
  parts.join
end

Private Instance Methods

leading_content() click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 40
def leading_content
  content[0...endpoints.begin]
end
leading_marker() click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 48
def leading_marker
  marker :begin
end
marker(which_end) click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 56
def marker(which_end)
  format_str = %(<%s id="%s-%s"></%s>)
  format format_str, tag, identifier, which_end, tag
end
parts() click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 61
def parts
  [leading_content, leading_marker, inner, trailing_marker,
   trailing_content]
end
trailing_content() click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 44
def trailing_content
  content[endpoints.end..-1]
end
trailing_marker() click to toggle source
# File lib/prolog/services/replace_content/splitter/paired.rb, line 52
def trailing_marker
  marker :end
end