Class: WWW::Delicious::Tag

Inherits:
Element show all
Defined in:
lib/www/delicious/tag.rb

Overview

Delicious Tag

Represents a single Tag element.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#initialize

Constructor Details

This class inherits a constructor from WWW::Delicious::Element

Instance Attribute Details

#countObject

Returns value for count attribute. Value is always normalized to Fixnum.



35
36
37
# File 'lib/www/delicious/tag.rb', line 35

def count
  @count
end

#nameObject

Returns value for name attribute. Value is always normalized as lower string.



31
32
33
# File 'lib/www/delicious/tag.rb', line 31

def name
  @name
end

Class Method Details

.from_rexml(element) ⇒ Object

Creates and returns new instance from a REXML element.

Implements Element#from_rexml.

Raises:

  • (ArgumentError)


88
89
90
91
92
93
94
# File 'lib/www/delicious/tag.rb', line 88

def from_rexml(element)
  raise ArgumentError, "`element` expected to be a `REXML::Element`" unless element.kind_of? REXML::Element
  self.new do |instance|
    instance.name  = element.if_attribute_value(:tag)
    instance.count = element.if_attribute_value(:count) { |value| value.to_i }
  end
end

Instance Method Details

#api_valid?Boolean

Returns wheter this object is valid for an API request.

To be valid name must not be empty. count can be 0.

Examples

tag = WWW::Delicious::Tag.new(:name => 'foo')
tag.api_api_valid?
# => true

tag = WWW::Delicious::Tag.new(:name => '  ')
tag.api_api_valid?
# => false

Returns:

  • (Boolean)


76
77
78
# File 'lib/www/delicious/tag.rb', line 76

def api_valid?
  return !name.empty?
end

#to_sObject

Returns a string representation of this Tag. In case name is nil this method will return an empty string.



54
55
56
# File 'lib/www/delicious/tag.rb', line 54

def to_s
  name.to_s
end