Class: NPR::Entity::Text
Instance Method Summary collapse
-
#initialize(json) ⇒ Text
constructor
—————–.
-
#to_html ⇒ Object
—————– Turn this text node into an embeddable block of HTML.
-
#to_s ⇒ Object
—————–.
Methods included from Concern::ShallowAttributes
Methods included from Concern::Relation
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_html ⇒ Object
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_s ⇒ Object
17 18 19 |
# File 'lib/npr/entity/text.rb', line 17 def to_s @paragraphs.map(&:to_s).join("\n") end |