• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / a7a7c677-70ce-4fb7-93a9-85b7a17ef43a

10 Dec 2024 07:51PM UTC coverage: 83.95% (-0.3%) from 84.203%
a7a7c677-70ce-4fb7-93a9-85b7a17ef43a

Pull #1097

circleci

carolyncole
Adding a tble to display the contents of a project
Pull Request #1097: Adding a table to display the contents of a project

4 of 4 branches covered (100.0%)

2 of 9 new or added lines in 2 files covered. (22.22%)

12 existing lines in 4 files now uncovered.

2223 of 2648 relevant lines covered (83.95%)

332.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/app/models/mediaflux/asset.rb
1
# frozen_string_literal: true
2
module Mediaflux
1✔
3
  class Asset
1✔
4
    attr_accessor :id, :path, :collection, :size
1✔
5

6
    def initialize(id:, name:, collection:, path: nil, last_modified_mf: nil, size: nil)
1✔
7
      @id = id
119✔
8
      @name = name
119✔
9
      @path = path
119✔
10
      @collection = collection
119✔
11
      @size = size
119✔
12
      @last_modified_mf = last_modified_mf
119✔
13
    end
14

15
    def name
1✔
16
      # Mediaflux supports the concept of files without a name and in those cases the
17
      # "name" property might be empty, but the actual name assigned internally by
18
      # Mediaflux (e.g. __asset_id__4665) is still reflected in the path.
19
      if @name == ""
85✔
20
        Pathname.new(path).basename.to_s
54✔
21
      else
22
        @name
31✔
23
      end
24
    end
25

26
    # Returns the path to the asset but without the root collection namespace as part of it.
27
    #
28
    # Example:
29
    #   path        -> "/tigerdata/projectg/folder1/file-abc.txt"
30
    #   path_short  -> "/projectg/folder1/file-abc.txt"
31
    def path_short
1✔
32
      return nil if path.nil?
82✔
33
      if path.starts_with?(Mediaflux::Connection.root_collection_namespace)
82✔
34
        path[Mediaflux::Connection.root_collection_namespace.length..-1]
82✔
35
      else
UNCOV
36
        path
×
37
      end
38
    end
39

40
    # Returns the last modified date but using the standard ISO 8601 (https://en.wikipedia.org/wiki/ISO_8601)
41
    def last_modified
1✔
42
      return nil if @last_modified_mf.nil?
80✔
43
      # https://nandovieira.com/working-with-dates-on-ruby-on-rails
44
      # Mediaflux dates are in UTC and look like this "07-Feb-2024 21:48:01"
45
      Object::Time.zone.parse(@last_modified_mf).in_time_zone("America/New_York").iso8601
80✔
46
    end
47

48
    # Returns the path for the asset
49
    # For a collection returns the path_short, but for a file is the dirname of the path_short
50
    #
51
    # Example for a file:
52
    #   path        -> "/tigerdata/projectg/folder1/file-abc.txt"
53
    #   path_short  -> "/projectg/folder1/file-abc.txt"
54
    #   path_only  -> "/projectg/folder1"
55
    # Example for a collection:
56
    #   path        -> "/tigerdata/projectg/folder1"
57
    #   path_short  -> "/projectg/folder1"
58
    #   path_only  -> "/projectg/folder1"
59
    def path_only
1✔
60
      return nil if path.nil?
80✔
61
      if collection
80✔
62
        path_short
19✔
63
      else
64
        p = Pathname.new(path_short)
61✔
65
        p.dirname.to_s
61✔
66
      end
67
    end
68
  end
69
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc