Sha256: 41277181c99d12d713b12e9922103d4e9566d5ae508a909039ccbace826d93b1

Contents?: true

Size: 909 Bytes

Versions: 15

Compression:

Stored size: 909 Bytes

Contents

module Ddr
  module HasContent
    extend ActiveSupport::Concern

    included do
      attribute :content, Ddr::File.optional
      attribute :fits_file, Ddr::File.optional

      delegate :original_filename, to: :content, allow_nil: true
    end

    def techmd
      @techmd ||= Ddr::Managers::TechnicalMetadataManager.new(self)
    end

    def content_size
      content&.file&.size
    end

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

    def content_type
      content&.media_type
    end

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

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

    def image?
      content_major_type == "image"
    end

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

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ddr-core-1.17.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.16.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.15.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.14.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.13.2 app/models/concerns/ddr/has_content.rb
ddr-core-1.13.1 app/models/concerns/ddr/has_content.rb
ddr-core-1.13.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.12.2 app/models/concerns/ddr/has_content.rb
ddr-core-1.12.1 app/models/concerns/ddr/has_content.rb
ddr-core-1.12.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.11.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.10.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.9.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.8.0 app/models/concerns/ddr/has_content.rb
ddr-core-1.7.0 app/models/concerns/ddr/has_content.rb