Module: OpenXml::HasProperties

Defined in:
lib/openxml/has_properties.rb

Defined Under Namespace

Modules: ClassMethods Classes: ChoiceGroupUniqueError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#build_required_propertiesObject



159
160
161
162
163
164
# File 'lib/openxml/has_properties.rb', line 159

def build_required_properties
  required_properties.each do |prop, default_value|
    public_send(:"#{prop}=", default_value) if respond_to? :"#{prop}="
    public_send(:"#{prop}")
  end
end

#initialize(*_args) ⇒ Object



124
125
126
127
# File 'lib/openxml/has_properties.rb', line 124

def initialize(*_args)
  super
  build_required_properties
end

#properties_attributesObject



133
134
135
# File 'lib/openxml/has_properties.rb', line 133

def properties_attributes
  properties_element.attributes
end

#properties_elementObject



129
130
131
# File 'lib/openxml/has_properties.rb', line 129

def properties_element
  @properties_element ||= self.class.properties_element.new
end

#property_xml(xml) ⇒ Object



149
150
151
152
153
154
155
156
157
# File 'lib/openxml/has_properties.rb', line 149

def property_xml(xml)
  ensure_required_choices
  props = active_properties
  return unless render_properties? props

  properties_element.to_xml(xml) do
    props.each { |prop| prop.to_xml(xml) }
  end
end

#render?Boolean

Returns:

  • (Boolean)


137
138
139
140
# File 'lib/openxml/has_properties.rb', line 137

def render?
  return true unless defined?(super)
  render_properties? || super
end

#to_xml(xml) ⇒ Object



142
143
144
145
146
147
# File 'lib/openxml/has_properties.rb', line 142

def to_xml(xml)
  super(xml) do
    property_xml(xml)
    yield xml if block_given?
  end
end