Class: BerkeleyLibrary::AV::Track

Inherits:
Object
  • Object
show all
Extended by:
Constants, Marc::Util
Includes:
Constants, Util, Comparable
Defined in:
lib/berkeley_library/av/track.rb

Constant Summary collapse

LABELS =
{
  SUBFIELD_CODE_DURATION => 'duration',
  SUBFIELD_CODE_TITLE => 'title',
  SUBFIELD_CODE_PATH => 'path'
}.freeze

Constants included from Util

Util::DEFAULT_USER_AGENT

Constants included from Constants

Constants::ALMA_RECORD_RE, Constants::MILLENNIUM_RECORD_RE, Constants::OCLC_RECORD_RE, Constants::SUBFIELD_CODES_TRACKS, Constants::SUBFIELD_CODE_ALMA_BIB_NUMBER, Constants::SUBFIELD_CODE_DURATION, Constants::SUBFIELD_CODE_PATH, Constants::SUBFIELD_CODE_TIND_BIB_NUMBER, Constants::SUBFIELD_CODE_TITLE, Constants::TAG_ALMA_MIGRATION_INFO, Constants::TAG_LINK_FIELD, Constants::TAG_TIND_CATALOG_ID, Constants::TAG_TIND_ID, Constants::TAG_TITLE_FIELD, Constants::TAG_TRACK_FIELD, Constants::UNKNOWN_TITLE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Marc::Util

group_subfield_values, group_subfields

Methods included from Util

#class_name, #compare_by_attributes, #compare_values, #do_get, #tidy_value

Constructor Details

#initialize(sort_order:, path:, title: nil, duration: nil) ⇒ Track

Returns a new instance of Track.



16
17
18
19
20
21
22
# File 'lib/berkeley_library/av/track.rb', line 16

def initialize(sort_order:, path:, title: nil, duration: nil)
  @sort_order = sort_order
  @title = title
  @path = path
  @duration = duration_or_nil(duration)
  @file_type = AV::Types::FileType.for_path(path)
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



14
15
16
# File 'lib/berkeley_library/av/track.rb', line 14

def duration
  @duration
end

#file_typeObject (readonly)

Returns the value of attribute file_type.



14
15
16
# File 'lib/berkeley_library/av/track.rb', line 14

def file_type
  @file_type
end

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/berkeley_library/av/track.rb', line 14

def path
  @path
end

#sort_orderObject (readonly)

Returns the value of attribute sort_order.



14
15
16
# File 'lib/berkeley_library/av/track.rb', line 14

def sort_order
  @sort_order
end

#titleObject (readonly)

Returns the value of attribute title.



14
15
16
# File 'lib/berkeley_library/av/track.rb', line 14

def title
  @title
end

Class Method Details

.tracks_from(marc_record, collection:) ⇒ Object

Note that if multiple tracks are encoded in the same 998 field, the subfields must be in the order :a, :t, :g (duration, title, path), as documented in “How to add media to the AV System”.

Parameters:

  • marc_record (MARC::Record)

    the MARC record

  • collection (String)

    the collection



75
76
77
78
79
80
81
82
83
# File 'lib/berkeley_library/av/track.rb', line 75

def tracks_from(marc_record, collection:)
  track_fields = marc_record.fields(TAG_TRACK_FIELD)
  track_fields.each_with_object([]) do |df, all_tracks|
    value_groups = group_values(df.subfields)
    value_groups.each do |group|
      all_tracks << from_value_group(group, collection:, sort_order: all_tracks.size)
    end
  end
end

Instance Method Details

#<=>(other) ⇒ Object



24
25
26
# File 'lib/berkeley_library/av/track.rb', line 24

def <=>(other)
  compare_by_attributes(self, other, :sort_order, :title, :duration, :path)
end

#inspectObject



37
38
39
# File 'lib/berkeley_library/av/track.rb', line 37

def inspect
  "\#<#{self.class.name} #{self}>"
end

#to_marc_subfieldsArray<MARC::Subfield>

Returns:

  • (Array<MARC::Subfield>)


42
43
44
45
46
47
48
# File 'lib/berkeley_library/av/track.rb', line 42

def to_marc_subfields
  [].tap do |subfields|
    subfields << MARC::Subfield.new(SUBFIELD_CODE_DURATION, duration.to_s) if duration
    subfields << MARC::Subfield.new(SUBFIELD_CODE_TITLE, title) if title
    subfields << MARC::Subfield.new(SUBFIELD_CODE_PATH, path)
  end
end

#to_sObject



28
29
30
31
32
33
34
35
# File 'lib/berkeley_library/av/track.rb', line 28

def to_s
  ''.tap do |s|
    s << "#{sort_order}: " if sort_order
    s << path
    s << " #{title.inspect}" if title
    s << " (#{duration})" if duration
  end
end