Class: Wiki::Api::PageBlock
- Inherits:
-
Object
- Object
- Wiki::Api::PageBlock
- Defined in:
- lib/wiki/api/page_block.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
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.
8 9 10 |
# File 'lib/wiki/api/page_block.rb', line 8 def initialize ={} self.elements = [] end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
6 7 8 |
# File 'lib/wiki/api/page_block.rb', line 6 def elements @elements end |
Instance Method Details
#<<(value) ⇒ Object
12 13 14 |
# File 'lib/wiki/api/page_block.rb', line 12 def << value self.elements << value end |
#links ⇒ Object
35 36 37 38 39 40 |
# File 'lib/wiki/api/page_block.rb', line 35 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 element: a end end |
#list_items ⇒ Object
28 29 30 31 32 33 |
# File 'lib/wiki/api/page_block.rb', line 28 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 element: list_item end end |
#to_texts ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wiki/api/page_block.rb', line 16 def to_texts # TODO: perhaps we should wrap the elements with objects?? 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 |