Class: Wordpressto::CategoryCollection

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wordpressto/category_collection.rb

Instance Method Summary collapse

Methods inherited from Base

#conn

Constructor Details

#initialize(*args) ⇒ CategoryCollection

Returns a new instance of CategoryCollection.



6
7
8
# File 'lib/wordpressto/category_collection.rb', line 6

def initialize(*args)
  super(*args)
end

Instance Method Details

#[](i) ⇒ Object



23
24
25
# File 'lib/wordpressto/category_collection.rb', line 23

def [](i)
  all[i]
end

#allObject



10
11
12
# File 'lib/wordpressto/category_collection.rb', line 10

def all
  @categories ||= load
end

#create(attributes) ⇒ Object



31
32
33
34
35
# File 'lib/wordpressto/category_collection.rb', line 31

def create(attributes)
  new_cat = Category.new(attributes, :conn => conn)
  new_cat.save
  new_cat
end

#eachObject



27
28
29
# File 'lib/wordpressto/category_collection.rb', line 27

def each
  all.each { |c| yield c }
end

#loadObject

retrieve the categories via xmlrpc



15
16
17
18
19
20
21
# File 'lib/wordpressto/category_collection.rb', line 15

def load
  cats = []
  conn.call('wp.getCategories', conn.blog_id, conn.username, conn.password).each do |c|
    cats << Category.new_from_xmlrpc(c, :conn => conn)
  end
  @categories = cats
end