Module: Blog::ContentRules::Helpers

Defined in:
app/services/blog/content_rules.rb

Overview

Helpers for rule implementations — wraps Nokogiri parsing so each rule
doesn't repeat boilerplate.

Class Method Summary collapse

Class Method Details

.parse(html) ⇒ Object



97
98
99
100
101
102
103
# File 'app/services/blog/content_rules.rb', line 97

def parse(html)
  if defined?(Nokogiri::HTML5)
    Nokogiri::HTML5.fragment(html.to_s)
  else
    Nokogiri::HTML.fragment(html.to_s)
  end
end

.text_only(html) ⇒ Object



105
106
107
# File 'app/services/blog/content_rules.rb', line 105

def text_only(html)
  parse(html).text.gsub(/\s+/, ' ').strip
end