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_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.



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

def relationship_key
  @relationship_key
end

#relationship_targetObject (readonly)

Returns the value of attribute relationship_target.



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

def relationship_target
  @relationship_target
end

#relationship_typeObject (readonly)

Returns the value of attribute relationship_type.



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

def relationship_type
  @relationship_type
end

Instance Method Details

#formatted_idObject

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


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

def formatted_id
  "rId#{ relationship_id }"
end

#formatted_targetObject



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

def formatted_target
  if relationship_type == :image
    ext = relationship_target.to_s.split('.').last
    "media/image#{ relationship_id }.#{ ext }"
  else
    relationship_target
  end
end

#formatted_typeObject



55
56
57
# File 'lib/caracal/core/models/relationship_model.rb', line 55

def formatted_type
  TYPE_MAP.fetch(relationship_type)
end

#id(value) ⇒ Object

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


62
63
64
# File 'lib/caracal/core/models/relationship_model.rb', line 62

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

#matches?(str) ⇒ Boolean

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

Returns:

  • (Boolean)


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

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

#target(value) ⇒ Object



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

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

#target_mode?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/caracal/core/models/relationship_model.rb', line 82

def target_mode?
  relationship_type == :link
end

#type(value) ⇒ Object



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

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

#valid?Boolean

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

Returns:

  • (Boolean)


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

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