Class: Mediaflux::Asset

Inherits:
Object
  • Object
show all
Defined in:
app/models/mediaflux/asset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, collection:, path: nil, last_modified_mf: nil, size: nil) ⇒ Asset

Returns a new instance of Asset.



6
7
8
9
10
11
12
13
# File 'app/models/mediaflux/asset.rb', line 6

def initialize(id:, name:, collection:, path: nil, last_modified_mf: nil, size: nil)
  @id = id
  @name = name
  @path = path
  @collection = collection
  @size = size
  @last_modified_mf = last_modified_mf
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



4
5
6
# File 'app/models/mediaflux/asset.rb', line 4

def collection
  @collection
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'app/models/mediaflux/asset.rb', line 4

def id
  @id
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'app/models/mediaflux/asset.rb', line 4

def path
  @path
end

#sizeObject

Returns the value of attribute size.



4
5
6
# File 'app/models/mediaflux/asset.rb', line 4

def size
  @size
end

Instance Method Details

#last_modifiedObject

Returns the last modified date but using the standard ISO 8601 (en.wikipedia.org/wiki/ISO_8601)



41
42
43
44
45
46
# File 'app/models/mediaflux/asset.rb', line 41

def last_modified
  return nil if @last_modified_mf.nil?
  # https://nandovieira.com/working-with-dates-on-ruby-on-rails
  # Mediaflux dates are in UTC and look like this "07-Feb-2024 21:48:01"
  Object::Time.zone.parse(@last_modified_mf).in_time_zone("America/New_York").iso8601
end

#nameObject



15
16
17
18
19
20
21
22
23
24
# File 'app/models/mediaflux/asset.rb', line 15

def name
  # Mediaflux supports the concept of files without a name and in those cases the
  # "name" property might be empty, but the actual name assigned internally by
  # Mediaflux (e.g. __asset_id__4665) is still reflected in the path.
  if @name == ""
    Pathname.new(path).basename.to_s
  else
    @name
  end
end

#path_onlyObject

Returns the path for the asset For a collection returns the path_short, but for a file is the dirname of the path_short

Example for a file:

path        -> "/tigerdata/projectg/folder1/file-abc.txt"
path_short  -> "/projectg/folder1/file-abc.txt"
path_only  -> "/projectg/folder1"

Example for a collection:

path        -> "/tigerdata/projectg/folder1"
path_short  -> "/projectg/folder1"
path_only  -> "/projectg/folder1"


59
60
61
62
63
64
65
66
67
# File 'app/models/mediaflux/asset.rb', line 59

def path_only
  return nil if path.nil?
  if collection
    path_short
  else
    p = Pathname.new(path_short)
    p.dirname.to_s
  end
end

#path_shortObject

Returns the path to the asset but without the root collection namespace as part of it.

Example:

path        -> "/tigerdata/projectg/folder1/file-abc.txt"
path_short  -> "/projectg/folder1/file-abc.txt"


31
32
33
34
35
36
37
38
# File 'app/models/mediaflux/asset.rb', line 31

def path_short
  return nil if path.nil?
  if path.starts_with?(Mediaflux::Connection.root_collection_namespace)
    path[Mediaflux::Connection.root_collection_namespace.length..-1]
  else
    path
  end
end