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?, #required_attributes

Class Attribute Details

.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



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

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

.namespace(*args) ⇒ Object



20
21
22
23
# File 'lib/openxml/element.rb', line 20

def namespace(*args)
  @namespace = args.first if args.any?
  @namespace ||= nil
end

.tag(*args) ⇒ Object



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

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

Instance Method Details

#nameObject



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

def name
  self.class.property_name || default_name
end

#namespaceObject



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

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

#tagObject



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

def tag
  self.class.tag || default_tag
end

#to_xml(xml) ⇒ Object



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

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