Class: Wikiwhat::Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, options = {}) ⇒ Page

Set title of article and type of information requested.

title - the title of the requested article as a String img_list - True if desired output is a list of all images on the page. header - the desired section header as a String. refs - True if desired output is a list of all references on the

page.

sidebar_img - True if desired output is the image in the sidebar paragraphs - the number of paragraphs from the article as an Interger

TODO sidebar - True if desired output is the contents of the sidebar.

Takes options hash and sets instance variables, then calls appropriate method.


25
26
27
28
29
# File 'lib/wikiwhat/page.rb', line 25

def initialize(title, options={})
  @title = title
  run(options)

end

Instance Attribute Details

#headObject (readonly)

Returns the value of attribute head.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def head
  @head
end

#header(header) ⇒ Object (readonly)

Returns the value of attribute header.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def header
  @header
end

#image_listObject (readonly)

Returns the value of attribute image_list.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def image_list
  @image_list
end

#img_listObject (readonly)

Returns the value of attribute img_list.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def img_list
  @img_list
end

#paragraphs(value = 1) ⇒ Object (readonly)

Memoized methods for each operation.

Returns instance variable or runs method.


60
61
62
# File 'lib/wikiwhat/page.rb', line 60

def paragraphs
  @paragraphs
end

#ref_listObject (readonly)

Returns the value of attribute ref_list.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def ref_list
  @ref_list
end

Returns the value of attribute sidebar_img_url.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def sidebar_img_url
  @sidebar_img_url
end

Returns the value of attribute sidebar_thumbnail.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def sidebar_thumbnail
  @sidebar_thumbnail
end

#titleObject (readonly)

Returns the value of attribute title.


7
8
9
# File 'lib/wikiwhat/page.rb', line 7

def title
  @title
end

Instance Method Details

#run(hash) ⇒ Object

Iterates over the options hash.

hash - options hash

Runs the appropriate method based on the options hash.


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wikiwhat/page.rb', line 36

def run(hash)
  hash.each do |key, value|
    case key
      when:img_list
        image_list
      when:header
        header(value)
      when:refs
        ref_list
      when:sidebar_img
        sidebar_image
      when:num_paragraphs
        paragraphs(value)
      when:sidebar
        sidebar_image
      when:sidebar_thumb
        sidebar_thumbnail(:width => value[:width], :height => value[:height])
    end
  end
end

76
77
78
# File 'lib/wikiwhat/page.rb', line 76

def sidebar_image
  @sidebar_image ||= find_sidebar_image
end