Class: OpenXml::Properties::BaseProperty
- Inherits:
-
Object
- Object
- OpenXml::Properties::BaseProperty
show all
- Defined in:
- lib/openxml/properties/base_property.rb
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
|
# File 'lib/openxml/properties/base_property.rb', line 32
def initialize(tag=nil, *_args)
return unless self.class.allowed_tags
validate_tag tag
@tag = tag
end
|
Class Attribute Details
Returns the value of attribute allowed_tags.
8
9
10
|
# File 'lib/openxml/properties/base_property.rb', line 8
def allowed_tags
@allowed_tags
end
|
.property_name ⇒ Object
Returns the value of attribute property_name.
7
8
9
|
# File 'lib/openxml/properties/base_property.rb', line 7
def property_name
@property_name
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
4
5
6
|
# File 'lib/openxml/properties/base_property.rb', line 4
def value
@value
end
|
Class Method Details
.name(*args) ⇒ Object
20
21
22
23
|
# File 'lib/openxml/properties/base_property.rb', line 20
def name(*args)
@property_name = args.first if args.any?
@property_name ||= nil
end
|
.namespace(*args) ⇒ Object
25
26
27
28
|
# File 'lib/openxml/properties/base_property.rb', line 25
def namespace(*args)
@namespace = args.first if args.any?
@namespace ||= nil
end
|
.tag(*args) ⇒ Object
15
16
17
18
|
# File 'lib/openxml/properties/base_property.rb', line 15
def tag(*args)
@tag = args.first if args.any?
@tag ||= nil
end
|
.tag_is_one_of(tags) ⇒ Object
10
11
12
13
|
# File 'lib/openxml/properties/base_property.rb', line 10
def tag_is_one_of(tags)
attr_accessor :tag
@allowed_tags = tags
end
|
Instance Method Details
#default_name ⇒ Object
52
53
54
|
# File 'lib/openxml/properties/base_property.rb', line 52
def default_name
class_name.gsub(/(.)([A-Z])/, '\1_\2').downcase
end
|
#default_tag ⇒ Object
60
61
62
|
# File 'lib/openxml/properties/base_property.rb', line 60
def default_tag
(class_name[0, 1].downcase + class_name[1..-1]).to_sym
end
|
#name ⇒ Object
48
49
50
|
# File 'lib/openxml/properties/base_property.rb', line 48
def name
self.class.property_name || default_name
end
|
#namespace ⇒ Object
64
65
66
|
# File 'lib/openxml/properties/base_property.rb', line 64
def namespace
self.class.namespace
end
|
#render? ⇒ Boolean
44
45
46
|
# File 'lib/openxml/properties/base_property.rb', line 44
def render?
!value.nil?
end
|
#tag ⇒ Object
56
57
58
|
# File 'lib/openxml/properties/base_property.rb', line 56
def tag
self.class.tag || default_tag
end
|
#validate_tag(tag) ⇒ Object
38
39
40
41
42
|
# File 'lib/openxml/properties/base_property.rb', line 38
def validate_tag(tag)
return if self.class.allowed_tags.include?(tag)
allowed = self.class.allowed_tags.join(", ")
raise ArgumentError, "Invalid tag name for #{name}: #{tag.inspect}. It should be one of #{allowed}."
end
|