Module: OpenXml::Docx::HasProperties::ClassMethods

Defined in:
lib/openxml/docx/has_properties.rb

Instance Method Summary collapse

Instance Method Details

#propertiesObject



48
49
50
# File 'lib/openxml/docx/has_properties.rb', line 48

def properties
  @properties ||= {}
end

#properties_tag(*args) ⇒ Object



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

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

#property(name, as: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/openxml/docx/has_properties.rb', line 30

def property(name, as: nil)
  properties[name] = (as || name).to_s

  class_eval <<-CODE, __FILE__, __LINE__ + 1
  def #{name}
    property_key = "#{name}".to_sym
    class_name = properties[property_key].split("_").map(&:capitalize).join
    prop_class = OpenXml::Docx::Properties.const_get class_name

    if instance_variable_get("@#{name}").nil?
      instance_variable_set "@#{name}", prop_class.new
    end

    instance_variable_get "@#{name}"
  end
  CODE
end

#value_property(name, as: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/openxml/docx/has_properties.rb', line 15

def value_property(name, as: nil)
  attr_reader name

  properties[name] = (as || name).to_s

  class_eval <<-CODE, __FILE__, __LINE__ + 1
  def #{name}=(value)
    property_key = "#{name}".to_sym
    class_name = properties[property_key].split("_").map(&:capitalize).join
    prop_class = OpenXml::Docx::Properties.const_get class_name
    instance_variable_set "@#{name}", prop_class.new(value)
  end
  CODE
end