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.



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

def count
  @count
end

#nameObject

Returns the value of attribute name.



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

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)


17
18
19
20
21
# File 'lib/mirrored/tag.rb', line 17

def 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:



6
7
8
9
10
11
# File 'lib/mirrored/tag.rb', line 6

def 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')


27
28
29
30
31
# File 'lib/mirrored/tag.rb', line 27

def 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