Class: NPR::Entity::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/npr/entity/text.rb

Instance Method Summary collapse

Methods included from Concern::ShallowAttributes

included

Methods included from Concern::Relation

included

Constructor Details

#initialize(json) ⇒ Text




11
12
13
# File 'lib/npr/entity/text.rb', line 11

def initialize(json)
  create_relations(json)
end

Instance Method Details

#to_htmlObject


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.



30
31
32
33
34
35
36
37
38
# File 'lib/npr/entity/text.rb', line 30

def to_html
  result = ""

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

  result
end

#to_sObject




17
18
19
# File 'lib/npr/entity/text.rb', line 17

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