Class: WWW::Delicious::Element

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

Overview

Abstract structure

Represent the most basic structure all Struc(s) must inherith from.

Direct Known Subclasses

Bundle, Post, Tag

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Element) initialize(attrs = {}) {|_self| ... }

Initializes a new instance and populate attributes from attrs.

class User < Element
  attr_accessor :first_name
  attr_accessor :last_name
end

User.new
User.new(:first_name => 'foo')
User.new(:first_name => 'John', :last_name => 'Doe')

You can even use a block. The following statements are equals:

User.new(:first_name => 'John', :last_name => 'Doe')

User.new do |user|
  user.first_name => 'John'
  user.last_name  => 'Doe'
end

Warning. In order to set an attribute a valid attribute writer must be available, otherwise this method will raise an exception.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(attrs = {}, &block)
  attrs.each { |key, value| self.send("#{key}=".to_sym, value) }
  yield self if block_given?
  self
end

Class Method Details

+ (Object) from_rexml(element, options)

Creates and returns new instance from a REXML element.

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/www/delicious/element.rb', line 64

def from_rexml(element, options)
  raise NotImplementedError
end