Class: HTML::Pipeline::ShortenFilter

Inherits:
AbbrFilter
  • Object
show all
Defined in:
lib/html/pipeline/shorten_filter.rb

Overview

Similar to abbreviate but it starts with the long format and shortens it

Constant Summary

Constants inherited from AbbrFilter

AbbrFilter::DEFAULT_IGNORED_ANCESTOR_TAGS, AbbrFilter::DEFINITION_PATTERN

Instance Method Summary collapse

Methods inherited from AbbrFilter

#call

Instance Method Details

#abbr_filter(content, abbr, full) ⇒ Object



17
18
19
20
# File 'lib/html/pipeline/shorten_filter.rb', line 17

def abbr_filter(content, abbr, full)
  target_html = abbr_tag(abbr, full)
  content.gsub(full) { |_| target_html }
end

#abbrs_filter(content, abbrs) ⇒ String

Return html with abbreviations replaced

Returns:

  • (String)

    html with all abbreviations replaced



10
11
12
13
14
15
# File 'lib/html/pipeline/shorten_filter.rb', line 10

def abbrs_filter(content, abbrs)
  abbrs.each do |abbr, full|
    content = abbr_filter(content, abbr, full) if content.include?(full)
  end
  content
end