Class: Mirrored::Tag

Inherits:
Base
  • Object
show all
Defined in:
lib/mirrored/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

api_url, connection, establish_connection, remove_connection, service, valid_service?

Instance Attribute Details

#countObject

Returns the value of attribute count.



30
31
32
# File 'lib/mirrored/tag.rb', line 30

def count
  @count
end

#nameObject

Returns the value of attribute name.



30
31
32
# File 'lib/mirrored/tag.rb', line 30

def name
  @name
end

Class Method Details

.find(*args) ⇒ Object

Does all the hard work finding your tags and how much you’ve used them.

Usage:

Mirrored::Tag.find(:get)

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/mirrored/tag.rb', line 14

def self.find(*args)
  raise ArgumentError, "Only takes a symbol as the argument (:get, :all)" unless args.first.kind_of?(Symbol)
  doc = Hpricot::XML(connection.get('tags/get'))
  (doc/:tag).inject([]) { |elements, el| elements << Tag.new_from_xml(el); elements }
end

.new_from_xml(xml) ⇒ Object

:nodoc:



3
4
5
6
7
8
# File 'lib/mirrored/tag.rb', line 3

def self.new_from_xml(xml) #:nodoc:
  t       = Tag.new
  t.count = (xml)['count']
  t.name  = (xml)['tag']
  t
end

.rename(old_name, new_name) ⇒ Object

Renames a tag from the old name to a new one.

Usage:

Mirrored::Tag.rename('microsoft', 'suckfest')


24
25
26
27
28
# File 'lib/mirrored/tag.rb', line 24

def self.rename(old_name, new_name)
  doc    = Hpricot::XML(connection.get('tags/rename', :old => old_name, :new => new_name))
  result = (doc).at(:result)
  (result && result.inner_html == 'done') ? true : false
end