Class: Category

Inherits:
Object
  • Object
show all
Defined in:
lib/rbmediawiki/category.rb

Overview

This class represents a category and performs actions dealing with categories.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title = nil, site = nil, id = nil) ⇒ Category

Returns a new instance of Category.



6
7
8
9
10
# File 'lib/rbmediawiki/category.rb', line 6

def initialize(title = nil, site = nil, id = nil)
    @site = site ? site : Api.new()
    @title = title.gsub(" ","_")
    @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/rbmediawiki/category.rb', line 5

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/rbmediawiki/category.rb', line 4

def title
  @title
end

Instance Method Details

#get_members(cmlimit = 500) ⇒ Object

get pages in the category as an array of Page elements returns false if there aren’t any, and raises NoPage if page doesn’t exist



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rbmediawiki/category.rb', line 14

def get_members(cmlimit = 500)
    cmcontinue = nil
    cms = Array.new
    loop {
        result = @site.query_list_categorymembers(@title, @title, nil, nil, cmcontinue, cmlimit)
        if result.key?('error') || !result['query']['categorymembers'].has_key?('cm')
            raise NoPage.new(), "Page [[#{@title}]] does not exist"
        end
        if result['query']['categorymembers']['cm'].is_a? Array
            cms = cms + result['query']['categorymembers']['cm']
        else
            cms.push(result['query']['categorymembers']['cm'])
        end
        if result.key?('query-continue')
            cmcontinue = result['query-continue']['categorymembers']['cmcontinue']
        else
            break
        end
    }
    return cms
end