Module: OBIX::Tag

Included in:
Objects::Base
Defined in:
lib/obix/tag.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, options = {}) ⇒ Object

Define a method for accessing the given attribute.

name - A Symbol describing the name of the attribute. options - A Hash of query options:

:type - A class describing the type of this attribute (defaults to nil).


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/obix/tag.rb', line 20

def attribute name, options = {}
  klass   = options.fetch :type, nil
  default = options.fetch :default, nil

  name = name.to_s.underscore

  define_method name do
    value = @attributes[name] || default

    if klass
      type = klass.new self
      type.cast value
    else
      value
    end
  end

  define_method "#{name}=" do |value|
    @attributes.store name, value
  end
end

#tag(name) ⇒ Object

Define a method for accessing the name of the tag.

name - A Symbol or String describing the name of the tag.



9
10
11
12
13
# File 'lib/obix/tag.rb', line 9

def tag name
  define_method :tag do
    name
  end
end