Class: Ddr::Models::Structures::File

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ddr/models/structures/file.rb

Overview

Wraps a Nokogiri (XML) ‘file’ node

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(args) ⇒ Object



40
41
42
43
44
45
# File 'lib/ddr/models/structures/file.rb', line 40

def self.build(args)
  node = Nokogiri::XML::Node.new('file', args[:document])
  node['ID'] = args[:id] if args[:id]
  node['USE'] = args[:use] if args[:use]
  node
end

.find(structure, fileid) ⇒ Object



47
48
49
# File 'lib/ddr/models/structures/file.rb', line 47

def self.find(structure, fileid)
  structure.files[fileid]
end

Instance Method Details

#effective_useObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ddr/models/structures/file.rb', line 23

def effective_use
  if use
    use
  else
    case parent.name
      when "file"
        File.new(parent).effective_use
      when "fileGrp"
        FileGrp.new(parent).effective_use
    end
  end
end

#filesObject



15
16
17
# File 'lib/ddr/models/structures/file.rb', line 15

def files
  xpath('xmlns:file').map { |node| File.new(node) }
end

#flocatsObject



19
20
21
# File 'lib/ddr/models/structures/file.rb', line 19

def flocats
  xpath('xmlns:FLocat').map { |node| FLocat.new(node) }
end

#idObject



7
8
9
# File 'lib/ddr/models/structures/file.rb', line 7

def id
  self['ID']
end

#repo_idsObject



36
37
38
# File 'lib/ddr/models/structures/file.rb', line 36

def repo_ids
  flocats.map(&:repo_id)
end

#useObject



11
12
13
# File 'lib/ddr/models/structures/file.rb', line 11

def use
  self['USE']
end