Class: OpenXml::Docx::Properties::BaseProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/openxml/docx/properties/base_property.rb

Direct Known Subclasses

ComplexProperty, ContainerProperty, Tab, ValueProperty

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag = nil, *args) ⇒ BaseProperty

Returns a new instance of BaseProperty.


32
33
34
35
36
37
38
# File 'lib/openxml/docx/properties/base_property.rb', line 32

def initialize(tag=nil, *args)
  return unless self.class.allowed_tags
  unless self.class.allowed_tags.include?(tag)
    raise ArgumentError, "Invalid tag name for #{name}: #{tag.inspect}. It should be one of #{self.class.allowed_tags.join(", ")}."
  end
  @tag = tag
end

Class Attribute Details

.allowed_tagsObject (readonly)

Returns the value of attribute allowed_tags


9
10
11
# File 'lib/openxml/docx/properties/base_property.rb', line 9

def allowed_tags
  @allowed_tags
end

.property_nameObject (readonly)

Returns the value of attribute property_name


8
9
10
# File 'lib/openxml/docx/properties/base_property.rb', line 8

def property_name
  @property_name
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value


5
6
7
# File 'lib/openxml/docx/properties/base_property.rb', line 5

def value
  @value
end

Class Method Details

.name(*args) ⇒ Object


21
22
23
24
# File 'lib/openxml/docx/properties/base_property.rb', line 21

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

.namespace(*args) ⇒ Object


26
27
28
29
# File 'lib/openxml/docx/properties/base_property.rb', line 26

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

.tag(*args) ⇒ Object


16
17
18
19
# File 'lib/openxml/docx/properties/base_property.rb', line 16

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

.tag_is_one_of(tags) ⇒ Object


11
12
13
14
# File 'lib/openxml/docx/properties/base_property.rb', line 11

def tag_is_one_of(tags)
  attr_accessor :tag
  @allowed_tags = tags
end

Instance Method Details

#default_nameObject


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

def default_name
  class_name.gsub(/(.)([A-Z])/, '\1_\2').downcase
end

#default_namespaceObject


64
65
66
# File 'lib/openxml/docx/properties/base_property.rb', line 64

def default_namespace
  :w
end

#default_tagObject


56
57
58
# File 'lib/openxml/docx/properties/base_property.rb', line 56

def default_tag
  (class_name[0, 1].downcase + class_name[1..-1]).to_sym
end

#nameObject


44
45
46
# File 'lib/openxml/docx/properties/base_property.rb', line 44

def name
  self.class.property_name || default_name
end

#namespaceObject


60
61
62
# File 'lib/openxml/docx/properties/base_property.rb', line 60

def namespace
  self.class.namespace || default_namespace
end

#render?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/openxml/docx/properties/base_property.rb', line 40

def render?
  !value.nil?
end

#tagObject


52
53
54
# File 'lib/openxml/docx/properties/base_property.rb', line 52

def tag
  self.class.tag || default_tag
end