Class: ROF::Filters::Work

Inherits:
Object
  • Object
show all
Defined in:
lib/rof/filters/work.rb

Overview

Expand objects of type “Work(-(.+))?” into a constellation of “fobjects”. Makes a fobject/generic_file for each file adds a depositor turns original object into an fobject/$1 and copies the access to each fobject.

Defined Under Namespace

Classes: NoFile

Instance Method Summary collapse

Constructor Details

#initializeWork

Returns a new instance of Work.



15
16
17
# File 'lib/rof/filters/work.rb', line 15

def initialize
  @utility = ROF::Utility.new
end

Instance Method Details

#make_thumbnail(result, main_obj, input_obj) ⇒ Object

make the first file be the representative thumbnail



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rof/filters/work.rb', line 41

def make_thumbnail(result, main_obj, input_obj)
  thumb_rep = nil
  input_obj['files'].each do |finfo|
    if finfo.is_a?(String)
      fname = finfo
      finfo = { 'files' => [fname] }
    else
      fname = finfo['files'].first
      raise NoFile if fname.nil?
    end
    finfo['rights'] ||= input_obj['rights']
    finfo['owner'] ||= input_obj['owner']
    finfo['bendo-item'] ||= input_obj['bendo-item']
    finfo['metadata'] ||= {
      '@context' => ROF::RdfContext
    }
    finfo['metadata']['dc:title'] ||= fname
    mimetype = MIME::Types.of(fname)
    mimetype = mimetype.empty? ? 'application/octet-stream' : mimetype.first.content_type
    f_obj = {
      'type' => 'fobject',
      'af-model' => 'GenericFile',
      'pid' => finfo['pid'],
      'bendo-item' => finfo['bendo-item'],
      'rights' => finfo['rights'],
      'properties' => ROF::Utility.prop_ds(finfo['owner']),
      'properties-meta' => {
        'mime-type' => 'text/xml'
      },
      'rels-ext' => {
        'isPartOf' => [main_obj['pid']]
      },
      'content-file' => fname,
      'content-meta' => {
        'label' => fname,
        'mime-type' => mimetype
      },
      'collections' => finfo['collections'],
      'metadata' => finfo['metadata']
    }
    f_obj.delete_if { |_k, v| v.nil? }
    if thumb_rep.nil?
      thumb_rep = f_obj['pid']
      if thumb_rep.nil?
        thumb_rep = @utility.next_label
        f_obj['pid'] = thumb_rep
      end
      main_obj['properties'] = ROF::Utility.prop_ds(input_obj['owner'], thumb_rep)
    end
    result << f_obj
  end
  result
end

#process(obj_list, filename) ⇒ Object

wade through object list



20
21
22
23
24
# File 'lib/rof/filters/work.rb', line 20

def process(obj_list, filename)
  @utility.set_workdir(filename)
  obj_list.map! { |x| process_one_work(x) }
  obj_list.flatten!
end

#process_one_work(input_obj) ⇒ Object

given a single object, return a list (possibly empty) of new objects to replace the one given



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rof/filters/work.rb', line 28

def process_one_work(input_obj)
  model = @utility.decode_work_type(input_obj)
  return [input_obj] if model.nil?
  return [ROF::Collection.process_one_collection(input_obj, @utility)] if model == 'Collection'

  main_obj = set_main_obj(input_obj, model)

  result = [main_obj]
  result = make_thumbnail(result, main_obj, input_obj) unless input_obj['files'].nil?
  result
end

#set_main_obj(input_obj, model) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rof/filters/work.rb', line 95

def set_main_obj(input_obj, model)
  result = {}

  result['type'] = 'fobject'
  result['af-model'] = model
  result['pid'] = input_obj.fetch('pid', @utility.next_label)
  result['bendo-item'] = input_obj['bendo-item']
  result['rights'] = input_obj['rights']
  result['properties'] = ROF::Utility.prop_ds(input_obj['owner'])
  result['properties-meta'] = { 'mime-type' => 'text/xml' }
  result['rels-ext'] = input_obj.fetch('rels-ext', {})
  result['metadata'] = input_obj['metadata']
  result
end