Class: OpenXml::Element

Inherits:
Object
  • Object
show all
Includes:
HasAttributes
Defined in:
lib/openxml/element.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasAttributes

#attributes, included, #render?

Class Attribute Details

.namespace(*args) ⇒ Object (readonly)

Returns the value of attribute namespace.



9
10
11
# File 'lib/openxml/element.rb', line 9

def namespace
  @namespace
end

.property_nameObject (readonly)

Returns the value of attribute property_name.



8
9
10
# File 'lib/openxml/element.rb', line 8

def property_name
  @property_name
end

Class Method Details

.name(*args) ⇒ Object



16
17
18
19
# File 'lib/openxml/element.rb', line 16

def name(*args)
  @property_name = args.first if args.any?
  @name
end

.tag(*args) ⇒ Object



11
12
13
14
# File 'lib/openxml/element.rb', line 11

def tag(*args)
  @tag = args.first if args.any?
  @tag
end

Instance Method Details

#nameObject



32
33
34
# File 'lib/openxml/element.rb', line 32

def name
  self.class.property_name || default_name
end

#namespaceObject



36
37
38
# File 'lib/openxml/element.rb', line 36

def namespace
  ([self.class] + self.class.ancestors).select { |klass| klass.respond_to?(:namespace) }.map(&:namespace).find(&:itself)
end

#tagObject



28
29
30
# File 'lib/openxml/element.rb', line 28

def tag
  self.class.tag || default_tag
end

#to_xml(xml) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/openxml/element.rb', line 40

def to_xml(xml)
  raise UndefinedNamespaceError, self.class unless namespace

  xml[namespace].public_send(tag, xml_attributes) do
    yield xml if block_given?
  end
end