Sha256: fa76c811cd46c6fabeebca21fe2407d54e12440e8f1a14ea6cfea24106d08b92

Contents?: true

Size: 859 Bytes

Versions: 18

Compression:

Stored size: 859 Bytes

Contents

module Wovnrb
  class HtmlReplaceMarker
    KEY_PREFIX = '__wovn-backend-ignored-key-'.freeze

    def initialize
      @current_key_number = 0
      @mapped_values = []
    end

    # Add argument's value to mapping information with comment style key
    def add_comment_value(value)
      key = "<!-- #{generate_key} -->"
      @mapped_values << [key, value]

      key
    end

    def add_value(value)
      key = generate_key
      @mapped_values << [key, value]

      key
    end

    def revert(marked_html)
      i = @mapped_values.size
      while i > 0
        i -= 1
        key, value = @mapped_values[i]
        marked_html = marked_html.sub(key, value)
      end
      marked_html
    end

    private

    def generate_key
      next_key = "#{KEY_PREFIX}#{@current_key_number}"
      @current_key_number += 1

      next_key
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
wovnrb-3.8.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.7.2 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.7.1 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.6.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.5.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.4.1 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.4.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.3.1 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.2.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.1.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.0.3 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.0.1 lib/wovnrb/services/html_replace_marker.rb
wovnrb-3.0.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-2.6.0 lib/wovnrb/services/html_replace_marker.rb
wovnrb-2.5.1 lib/wovnrb/services/html_replace_marker.rb
wovnrb-2.2.4 lib/wovnrb/services/html_replace_marker.rb
wovnrb-2.2.3 lib/wovnrb/services/html_replace_marker.rb
wovnrb-2.2.2 lib/wovnrb/services/html_replace_marker.rb