Class: Wiki::Api::Page

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Page

Returns a new instance of Page.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/wiki/api/page.rb', line 8

def initialize(options={})
  self.name = options[:name] if options.include? :name
  uri = options[:uri] if options.include? :uri

  @@config ||= nil
  if @@config.nil? || !uri.nil?
    # use the connection to collect HTML pages for parsing
    @connect = Wiki::Api::Connect.new uri: uri
  else
    # using a local HTML file for parsing
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/wiki/api/page.rb', line 6

def name
  @name
end

#parsed_pageObject

Returns the value of attribute parsed_page.



6
7
8
# File 'lib/wiki/api/page.rb', line 6

def parsed_page
  @parsed_page
end

#uriObject

Returns the value of attribute uri.



6
7
8
# File 'lib/wiki/api/page.rb', line 6

def uri
  @uri
end

Class Method Details

.config=(config = {}) ⇒ Object



59
60
61
# File 'lib/wiki/api/page.rb', line 59

def config=(config = {})
  @@config = config
end

Instance Method Details

#headline(headline_name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wiki/api/page.rb', line 34

def headline headline_name
  headlines = []
  self.parse_blocks(headline_name).each do |headline_name, elements|
    headline = PageHeadline.new name: headline_name
    elements.each do |element|
      # nokogiri element
      headline.block << element
    end
    headlines << headline
  end
  headlines
end

#headlinesObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/wiki/api/page.rb', line 21

def headlines
  headlines = []
  self.parse_blocks.each do |headline_name, elements|
    headline = PageHeadline.new name: headline_name
    elements.each do |element|
      # nokogiri element
      headline.block << element
    end
    headlines << headline
  end
  headlines
end

#reset!Object



54
55
56
# File 'lib/wiki/api/page.rb', line 54

def reset!
  self.parse_page = nil
end

#to_htmlObject



49
50
51
52
# File 'lib/wiki/api/page.rb', line 49

def to_html
  self.load_page!
  self.parsed_page.to_xhtml indent: 3, indent_text: " "
end