Module: Ddr::Models::HasContent

Extended by:
ActiveSupport::Concern
Included in:
Attachment, Component, Target
Defined in:
lib/ddr/models/has_content.rb

Instance Method Summary collapse

Instance Method Details

#content_changed?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/ddr/models/has_content.rb', line 87

def content_changed?
  content.external? ? content.dsLocation_changed? : content.content_changed?
end

#content_human_sizeObject



45
46
47
# File 'lib/ddr/models/has_content.rb', line 45

def content_human_size
  ActiveSupport::NumberHelper.number_to_human_size(content_size) if content_size
end

#content_major_typeObject



53
54
55
# File 'lib/ddr/models/has_content.rb', line 53

def content_major_type
  content_type.split("/").first
end

#content_sizeObject



41
42
43
# File 'lib/ddr/models/has_content.rb', line 41

def content_size
  content.external? ? content.file_size : content.dsSize
end

#content_sub_typeObject



57
58
59
# File 'lib/ddr/models/has_content.rb', line 57

def content_sub_type
  content_type.split("/").last
end

#content_typeObject



49
50
51
# File 'lib/ddr/models/has_content.rb', line 49

def content_type
  content.mimeType
end

#content_type=(mime_type) ⇒ Object



61
62
63
# File 'lib/ddr/models/has_content.rb', line 61

def content_type= mime_type
  self.content.mimeType = mime_type
end

#generate_thumbnailObject



73
74
75
76
77
# File 'lib/ddr/models/has_content.rb', line 73

def generate_thumbnail
  return false unless thumbnailable?
  transform_datastream :content, { thumbnail: { size: "100x100>", datastream: "thumbnail" } }
  thumbnail_changed?
end

#generate_thumbnail!Object



79
80
81
# File 'lib/ddr/models/has_content.rb', line 79

def generate_thumbnail!
  generate_thumbnail && save
end

#image?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/ddr/models/has_content.rb', line 65

def image?
  content_major_type == "image"
end

#pdf?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/ddr/models/has_content.rb', line 69

def pdf?
  content_type == "application/pdf"
end

#upload(file, opts = {}) ⇒ Object

Convenience method wrapping FileManagement#add_file



31
32
33
# File 'lib/ddr/models/has_content.rb', line 31

def upload file, opts={}
  add_file(file, Ddr::Datastreams::CONTENT, opts)
end

#upload!(file, opts = {}) ⇒ Object

Set content to file and save



36
37
38
39
# File 'lib/ddr/models/has_content.rb', line 36

def upload! file, opts={}
  upload(file, opts)
  save
end

#virus_checksObject



83
84
85
# File 'lib/ddr/models/has_content.rb', line 83

def virus_checks
  Ddr::Events::VirusCheckEvent.for_object(self)
end