Class: Ddr::Managers::TechnicalMetadataManager

Inherits:
Manager
  • Object
show all
Defined in:
lib/ddr/managers/technical_metadata_manager.rb

Constant Summary collapse

FITS_141_TIMESTAMP_FORMAT =

Ex. 7/3/15 8:29 PM

"%D %l:%M %p"
FITS_150_TIMESTAMP_FORMAT =

Ex. 7/3/15, 8:29 PM

"%D, %l:%M %p"
FITS_TIMESTAMP_FORMATS =
[ FITS_141_TIMESTAMP_FORMAT, FITS_150_TIMESTAMP_FORMAT ]

Instance Attribute Summary

Attributes inherited from Manager

#object

Instance Method Summary collapse

Methods inherited from Manager

#initialize

Constructor Details

This class inherits a constructor from Ddr::Managers::Manager

Instance Method Details

#checksum_digestObject

Ddr::File currently implements the ‘digest’ attribute as a set (array) of Ddr::Digest objects. This method (and the ‘checksum_value’ method that follows) assumes there is only one checksum associated with a file (as was the case in ddr-models). The current implementation simply picks the first checksum, unless/until we decide on a different approach.



77
78
79
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 77

def checksum_digest
  content&.digest&.first&.type
end

#checksum_valueObject



81
82
83
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 81

def checksum_value
  content&.digest&.first&.value
end

#creation_timeObject



101
102
103
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 101

def creation_time
  created.map { |datestr| coerce_to_time(datestr) }.compact
end

#file_human_sizeObject



61
62
63
64
65
66
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 61

def file_human_size
  file_size.map do |fs|
    "%s (%s bytes)" % [ ActiveSupport::NumberHelper.number_to_human_size(fs),
                        ActiveSupport::NumberHelper.number_to_delimited(fs) ]
  end
end

#file_sizeObject



57
58
59
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 57

def file_size
  extent.map(&:to_i)
end

#fitsObject



30
31
32
33
34
35
36
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 30

def fits
  if object.fits_file.present?
    Ddr::Fits.new(Nokogiri::XML(object.fits_file.file))
  else
    Ddr::Fits.new(Ddr::Fits.xml_template)
  end
end

#fits?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 38

def fits?
  !fits_version.nil?
end

#fits_datetimeObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 46

def fits_datetime
  if fits_timestamp = fits.timestamp.first
    parsed = nil
    FITS_TIMESTAMP_FORMATS.each do |format|
      parsed = Time.zone.strptime(fits_timestamp, format) rescue nil
      break if parsed
    end
    parsed
  end
end

#fits_versionObject



42
43
44
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 42

def fits_version
  fits.version.first
end

#ill_formed?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 93

def ill_formed?
  well_formed.any? { |v| v == "false" }
end

#invalid?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 85

def invalid?
  valid.any? { |v| v == "false" }
end

#md5Object



68
69
70
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 68

def md5
  fits.md5.first
end

#modification_timeObject



105
106
107
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 105

def modification_time
  modified.map { |datestr| coerce_to_time(datestr) }.compact
end

#valid?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 89

def valid?
  !invalid?
end

#well_formed?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/ddr/managers/technical_metadata_manager.rb', line 97

def well_formed?
  !ill_formed?
end