gottfrois/link_thumbnailer

View on GitHub
lib/link_thumbnailer/models/body.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require 'link_thumbnailer/model'

module LinkThumbnailer
  module Models
    class Body < ::LinkThumbnailer::Model

      attr_reader :node, :paragraphs

      def initialize(node, text = nil)
        @node = node
        @paragraphs = node.map{|n| sanitize(squish(n.text.to_s))}.reject{|n| n.empty?}
      end

      def to_s
        @paragraphs.join(' ')
      end

    end
  end
end