Class: Caracal::Core::Models::RelationshipModel
- Inherits:
-
BaseModel
- Object
- BaseModel
- Caracal::Core::Models::RelationshipModel
show all
- Defined in:
- lib/caracal/core/models/relationship_model.rb
Overview
This class encapsulates the logic needed to store and manipulate relationship data.
Constant Summary
collapse
- TYPE_MAP =
{
font: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable',
footer: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer',
header: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/header',
image: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image',
link: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink',
numbering: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering',
setting: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings',
style: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles'
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from BaseModel
#initialize
Instance Attribute Details
#relationship_data ⇒ Object
Returns the value of attribute relationship_data.
34
35
36
|
# File 'lib/caracal/core/models/relationship_model.rb', line 34
def relationship_data
@relationship_data
end
|
#relationship_id ⇒ Object
30
31
32
|
# File 'lib/caracal/core/models/relationship_model.rb', line 30
def relationship_id
@relationship_id
end
|
#relationship_key ⇒ Object
Returns the value of attribute relationship_key.
31
32
33
|
# File 'lib/caracal/core/models/relationship_model.rb', line 31
def relationship_key
@relationship_key
end
|
#relationship_target ⇒ Object
Returns the value of attribute relationship_target.
33
34
35
|
# File 'lib/caracal/core/models/relationship_model.rb', line 33
def relationship_target
@relationship_target
end
|
#relationship_type ⇒ Object
Returns the value of attribute relationship_type.
32
33
34
|
# File 'lib/caracal/core/models/relationship_model.rb', line 32
def relationship_type
@relationship_type
end
|
Instance Method Details
#data(value) ⇒ Object
78
79
80
|
# File 'lib/caracal/core/models/relationship_model.rb', line 78
def data(value)
@relationship_data = value.to_s
end
|
GETTERS =============================
44
45
46
|
# File 'lib/caracal/core/models/relationship_model.rb', line 44
def formatted_id
"rId#{ relationship_id }"
end
|
48
49
50
51
52
53
54
55
56
|
# File 'lib/caracal/core/models/relationship_model.rb', line 48
def formatted_target
if relationship_type == :image
ext = relationship_target.to_s.split('.').last
ext = ext.split('?').first
"media/image#{ relationship_id }.#{ ext }"
else
relationship_target
end
end
|
58
59
60
|
# File 'lib/caracal/core/models/relationship_model.rb', line 58
def formatted_type
TYPE_MAP.fetch(relationship_type)
end
|
#id(value) ⇒ Object
SETTERS =============================
65
66
67
|
# File 'lib/caracal/core/models/relationship_model.rb', line 65
def id(value)
@relationship_id = value.to_i
end
|
#matches?(str) ⇒ Boolean
STATE ===============================
85
86
87
|
# File 'lib/caracal/core/models/relationship_model.rb', line 85
def matches?(str)
relationship_key.downcase == str.to_s.downcase
end
|
#target(value) ⇒ Object
73
74
75
76
|
# File 'lib/caracal/core/models/relationship_model.rb', line 73
def target(value)
@relationship_target = value.to_s
@relationship_key = value.to_s.downcase
end
|
#target_mode? ⇒ Boolean
89
90
91
|
# File 'lib/caracal/core/models/relationship_model.rb', line 89
def target_mode?
relationship_type == :link
end
|
#type(value) ⇒ Object
69
70
71
|
# File 'lib/caracal/core/models/relationship_model.rb', line 69
def type(value)
@relationship_type = value.to_s.downcase.to_sym
end
|
#valid? ⇒ Boolean
VALIDATION ===========================
96
97
98
99
|
# File 'lib/caracal/core/models/relationship_model.rb', line 96
def valid?
required = [:id, :target, :type]
required.all? { |m| !send("relationship_#{ m }").nil? }
end
|