Class: Rave::Models::Element

Inherits:
Component show all
Includes:
Rave::Mixins::ObjectFactory
Defined in:
lib/models/element.rb

Overview

An element within a document. (abstract factory)

Direct Known Subclasses

Form, Gadget, Image, InlineBlip

Defined Under Namespace

Classes: Form, Gadget, Image, InlineBlip

Constant Summary collapse

JAVA_CLASS =
"com.google.wave.api.FormElement"

Constants included from Rave::Mixins::ObjectFactory

Rave::Mixins::ObjectFactory::WILDCARD

Constants inherited from Component

Component::GENERATED_PATTERN, Component::GENERATED_PREFIX

Instance Attribute Summary

Attributes included from Rave::Mixins::ObjectFactory

#type

Attributes inherited from Component

#context

Instance Method Summary collapse

Methods included from Rave::Mixins::ObjectFactory

included

Methods inherited from Component

#generated?, #id, #to_s, #unique_id

Methods included from Rave::Mixins::Logger

#logger

Constructor Details

#initialize(properties = {}) ⇒ Element

Returns a new instance of Element.



10
11
12
13
# File 'lib/models/element.rb', line 10

def initialize(properties = {})
  super(:id => '') # TODO: Don't actually have IDs, as such. Bad inheritance from Component?
  @properties = properties
end

Instance Method Details

#get(key, default = nil) ⇒ Object Also known as: []

Gets the value of an element property.



16
17
18
19
20
21
22
# File 'lib/models/element.rb', line 16

def get(key, default = nil)
  if @properties.has_key? key
    @properties[key]
  else
    default
  end
end

#set(key, value) ⇒ Object Also known as: []=

Sets the value of an element property.



25
26
27
# File 'lib/models/element.rb', line 25

def set(key, value)
  @properties[key] = value
end

#to_jsonObject

:nodoc:



35
36
37
38
39
40
41
# File 'lib/models/element.rb', line 35

def to_json # :nodoc:
  {
    'javaClass' => JAVA_CLASS,
    'properties' => @properties,
    'type' => type,
  }.to_json
end