Class: ContentfulConverter::Nodes::Base
- Inherits:
-
Object
- Object
- ContentfulConverter::Nodes::Base
- Defined in:
- lib/contentful_converter/nodes/base.rb
Direct Known Subclasses
Blockquote, Document, Header, HorizontalLine, Hyperlink, ListItem, OrderedList, Paragraph, Text, UnorderedList
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#node_type ⇒ Object
readonly
Returns the value of attribute node_type.
-
#nokogiri_node ⇒ Object
readonly
Returns the value of attribute nokogiri_node.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_content(node) ⇒ Object
-
#initialize(nokogiri_node = nil, parent = nil) ⇒ Base
constructor
A new instance of Base.
- #needs_p_wrapping? ⇒ Boolean
- #to_h(params = options) ⇒ Object
Constructor Details
#initialize(nokogiri_node = nil, parent = nil) ⇒ Base
Returns a new instance of Base.
8 9 10 11 12 13 |
# File 'lib/contentful_converter/nodes/base.rb', line 8 def initialize(nokogiri_node = nil, parent = nil) @nokogiri_node = nokogiri_node @parent = parent @node_type = type @content = [] end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/contentful_converter/nodes/base.rb', line 6 def content @content end |
#node_type ⇒ Object (readonly)
Returns the value of attribute node_type.
6 7 8 |
# File 'lib/contentful_converter/nodes/base.rb', line 6 def node_type @node_type end |
#nokogiri_node ⇒ Object (readonly)
Returns the value of attribute nokogiri_node.
6 7 8 |
# File 'lib/contentful_converter/nodes/base.rb', line 6 def nokogiri_node @nokogiri_node end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/contentful_converter/nodes/base.rb', line 6 def parent @parent end |
Instance Method Details
#add_content(node) ⇒ Object
15 16 17 |
# File 'lib/contentful_converter/nodes/base.rb', line 15 def add_content(node) @content << (node.needs_p_wrapping? ? wrap_in_p(node) : node) end |
#needs_p_wrapping? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/contentful_converter/nodes/base.rb', line 26 def needs_p_wrapping? if parent.nil? || parent&.class == Nodes::Header || parent&.class == Nodes::Paragraph || parent&.class == Nodes::Hyperlink return false end true end |
#to_h(params = options) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/contentful_converter/nodes/base.rb', line 19 def to_h(params = ) params[:nodeType] = node_type params[:data] = params[:data] || {} params[:content] = content.map(&:to_h).compact params end |