Class: Caracal::Core::Models::RelationshipModel

Inherits:
BaseModel
  • Object
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 =

constants

{
  font:       'http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable', 
  footer:     'http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer',
  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

Constructor Details

This class inherits a constructor from Caracal::Core::Models::BaseModel

Instance Attribute Details

#relationship_dataObject (readonly)

Returns the value of attribute relationship_data.



33
34
35
# File 'lib/caracal/core/models/relationship_model.rb', line 33

def relationship_data
  @relationship_data
end

#relationship_idObject (readonly)

accessors



29
30
31
# File 'lib/caracal/core/models/relationship_model.rb', line 29

def relationship_id
  @relationship_id
end

#relationship_keyObject (readonly)

Returns the value of attribute relationship_key.



30
31
32
# File 'lib/caracal/core/models/relationship_model.rb', line 30

def relationship_key
  @relationship_key
end

#relationship_targetObject (readonly)

Returns the value of attribute relationship_target.



32
33
34
# File 'lib/caracal/core/models/relationship_model.rb', line 32

def relationship_target
  @relationship_target
end

#relationship_typeObject (readonly)

Returns the value of attribute relationship_type.



31
32
33
# File 'lib/caracal/core/models/relationship_model.rb', line 31

def relationship_type
  @relationship_type
end

Instance Method Details

#data(value) ⇒ Object



77
78
79
# File 'lib/caracal/core/models/relationship_model.rb', line 77

def data(value)
  @relationship_data = value.to_s
end

#formatted_idObject

GETTERS =============================


43
44
45
# File 'lib/caracal/core/models/relationship_model.rb', line 43

def formatted_id
  "rId#{ relationship_id }"
end

#formatted_targetObject



47
48
49
50
51
52
53
54
55
# File 'lib/caracal/core/models/relationship_model.rb', line 47

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

#formatted_typeObject



57
58
59
# File 'lib/caracal/core/models/relationship_model.rb', line 57

def formatted_type
  TYPE_MAP.fetch(relationship_type)
end

#id(value) ⇒ Object

SETTERS =============================


64
65
66
# File 'lib/caracal/core/models/relationship_model.rb', line 64

def id(value)
  @relationship_id = value.to_i
end

#matches?(str) ⇒ Boolean

STATE ===============================

Returns:

  • (Boolean)


84
85
86
# File 'lib/caracal/core/models/relationship_model.rb', line 84

def matches?(str)
  relationship_key.downcase == str.to_s.downcase
end

#target(value) ⇒ Object



72
73
74
75
# File 'lib/caracal/core/models/relationship_model.rb', line 72

def target(value)
  @relationship_target = value.to_s
  @relationship_key    = value.to_s.downcase
end

#target_mode?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/caracal/core/models/relationship_model.rb', line 88

def target_mode?
  relationship_type == :link
end

#type(value) ⇒ Object



68
69
70
# File 'lib/caracal/core/models/relationship_model.rb', line 68

def type(value)
  @relationship_type = value.to_s.downcase.to_sym
end

#valid?Boolean

VALIDATION ===========================

Returns:

  • (Boolean)


95
96
97
98
# File 'lib/caracal/core/models/relationship_model.rb', line 95

def valid?
  required = [:id, :target, :type]
  required.all? { |m| !send("relationship_#{ m }").nil? }
end