Class: Wordpressto::Category

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ Category

Returns a new instance of Category.



5
6
7
8
9
10
11
12
13
14
# File 'lib/wordpressto/category.rb', line 5

def initialize(attributes = {}, options = {})
  @id = attributes[:id]
  @category_id = attributes[:category_id] || 0
  @description = attributes[:description]
  @name = attributes[:name]
  @url = attributes[:url]
  @rss_url = attributes[:rss_url]
  @slug = attributes[:slug]
  @conn = options[:conn]
end

Instance Attribute Details

#category_idObject (readonly)

Returns the value of attribute category_id.



3
4
5
# File 'lib/wordpressto/category.rb', line 3

def category_id
  @category_id
end

#connObject (readonly)

Returns the value of attribute conn.



3
4
5
# File 'lib/wordpressto/category.rb', line 3

def conn
  @conn
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/wordpressto/category.rb', line 3

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/wordpressto/category.rb', line 3

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/wordpressto/category.rb', line 3

def name
  @name
end

#rss_urlObject (readonly)

Returns the value of attribute rss_url.



3
4
5
# File 'lib/wordpressto/category.rb', line 3

def rss_url
  @rss_url
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/wordpressto/category.rb', line 3

def url
  @url
end

Class Method Details

.new_from_xmlrpc(attributes, options = {}) ⇒ Object



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

def self.new_from_xmlrpc(attributes, options = {})
  self.new( { :id => attributes['categoryId'], :category_id => attributes['parentId'],
              :description => attributes['description'], :name => attributes['categoryName'],
              :url => attributes['htmlUrl'], :rss_url => attributes['rssUrl'] },
            options )
end

Instance Method Details

#saveObject



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

def save
  @id = conn.call 'wp.newCategory', conn.blog_id, conn.username, conn.password, to_xmlrpc_struct
end

#slugObject



31
32
33
# File 'lib/wordpressto/category.rb', line 31

def slug
  @slug ||= @name.to_s.downcase.strip.gsub(/\s/, '-')
end

#to_xmlrpc_structObject



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

def to_xmlrpc_struct
  { "name" => name, "slug" => slug, "parent_id" => category_id, "description" => description.to_s }
end