Class: Wiki::Api::PageBlock

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

Overview

Collection of elements for segmented per headline

Instance Attribute Summary collapse

Instance Method Summary collapse

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 options={}
  self.parent = options[:parent] if options.include? :parent
  self.elements = []
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



7
8
9
# File 'lib/wiki/api/page_block.rb', line 7

def elements
  @elements
end

#parentObject

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


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_itemsObject



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_textsObject



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