Sha256: 253540688a81f0c5de05af9adc867e5473c25ccde9ca8f3a42469bd898ac4a20

Contents?: true

Size: 863 Bytes

Versions: 5

Compression:

Stored size: 863 Bytes

Contents

##
# NPR::Entity::Text
#
module NPR
  module Entity
    class Text < Base
      has_many "paragraphs", :key => "paragraph", :class_name => NPR::Entity::Paragraph

      #-----------------

      def initialize(json)
        create_relations(json)
      end

      #-----------------

      def to_s
        @paragraphs.map(&:to_s).join("\n")
      end

      #-----------------
      # Turn this text node into an embeddable
      # block of HTML.
      #
      # This is useful if the fullText attribute
      # is missing on an NPR Story. It will not
      # be as robust as a full HTML body from
      # NPR, but it will work in most cases.
      #
      def to_html
        result = ""

        @paragraphs.each do |paragraph|
          result << "<p>" + paragraph.to_s + "</p>\n"
        end

        result
      end
    end # Text
  end # Entity
end # NPR

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
npr-3.0.0 lib/npr/entity/text.rb
npr-2.0.2 lib/npr/entity/text.rb
npr-2.0.1 lib/npr/entity/text.rb
npr-2.0.0 lib/npr/entity/text.rb
npr-1.2.0 lib/npr/entity/text.rb