Class: Wiki::Api::PageBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/wiki/api/page_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 options={}
  self.elements = []
end

Instance Attribute Details

#elementsObject

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


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_itemsObject



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_textsObject



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