Class: WWW::Delicious::Tag

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values_or_rexml) {|_self| ... } ⇒ Tag

Creates a new WWW::Delicious::Tag.

Yields:

  • (_self)

Yield Parameters:



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/www/delicious/tag.rb', line 34

def initialize(values_or_rexml, &block) # :yields: tag
  case values_or_rexml
  when Hash
    initialize_from_hash(values_or_rexml)
  when REXML::Element
    initialize_from_rexml(values_or_rexml)
  else
    raise ArgumentError, 'Expected `values_or_rexml` to be `Hash` or `REXML::Element`'
  end
  
  yield(self) if block_given?
  self
end

Instance Attribute Details

#countObject

The number of links tagged with this tag. It should be set only from an API response.



27
28
29
# File 'lib/www/delicious/tag.rb', line 27

def count
  @count
end

#nameObject

The name of the tag



23
24
25
# File 'lib/www/delicious/tag.rb', line 23

def name
  @name
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)


113
114
115
# File 'lib/www/delicious/tag.rb', line 113

def api_valid?
	return !name.empty?
end

#initialize_from_hash(values) ⇒ Object

Initializes WWW::Delicious::Tag from an Hash.



61
62
63
64
# File 'lib/www/delicious/tag.rb', line 61

def initialize_from_hash(values)
  self.name  = values[:name]
  self.count = values[:count]
end

#initialize_from_rexml(element) ⇒ Object

Initializes WWW::Delicious::Tag from a REXML fragment.



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

def initialize_from_rexml(element)
  self.name  = element.attribute_value(:tag)
  self.count = element.attribute_value(:count)
end

#to_sObject

Returns a string representation of this Tag.



91
92
93
# File 'lib/www/delicious/tag.rb', line 91

def to_s()
	return self.name
end