Class: Wiki::Api::PageBlock
- Inherits:
-
Object
- Object
- Wiki::Api::PageBlock
- Defined in:
- lib/wiki/api/page_block.rb
Overview
Collection of elements for segmented per headline
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #<<(value) ⇒ Object
-
#initialize(options = {}) ⇒ PageBlock
constructor
A new instance of PageBlock.
- #links ⇒ Object
- #list_items ⇒ Object
- #to_texts ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ PageBlock
Returns a new instance of PageBlock.
9 10 11 12 |
# File 'lib/wiki/api/page_block.rb', line 9 def initialize ={} self.parent = [:parent] if .include? :parent self.elements = [] end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
7 8 9 |
# File 'lib/wiki/api/page_block.rb', line 7 def elements @elements end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/wiki/api/page_block.rb', line 7 def parent @parent end |
Instance Method Details
#<<(value) ⇒ Object
14 15 16 17 |
# File 'lib/wiki/api/page_block.rb', line 14 def << value # value.first.previous.name self.elements << value end |
#links ⇒ Object
37 38 39 40 41 42 |
# File 'lib/wiki/api/page_block.rb', line 37 def links # TODO: perhaps we should wrap the elements with objects, and request a li per element?? self.search("a").map do |a| PageLink.new parent: self, element: a end end |
#list_items ⇒ Object
30 31 32 33 34 35 |
# File 'lib/wiki/api/page_block.rb', line 30 def list_items # TODO: perhaps we should wrap the elements with objects, and request a li per element?? self.search("li").map do |list_item| PageListItem.new parent: self, element: list_item end end |
#to_texts ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wiki/api/page_block.rb', line 19 def to_texts texts = [] self.elements.flatten.each do |element| text = Wiki::Api::Util.element_to_text element if element.is_a? Nokogiri::XML::Element next if text.nil? next if text.empty? texts << text end texts end |