Class: Mexico::FileSystem::Layer

Inherits:
Object
  • Object
show all
Includes:
Poseidon, ROXML
Defined in:
lib/mexico/file_system/layer.rb

Overview

A layer (or tier) in an transcription or annotation document.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Layer

data type content structure



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mexico/file_system/layer.rb', line 47

def initialize(args={})
  args.each do |k,v|
    if self.respond_to?("#{k}=")
      send("#{k}=", v)
    end

    @properties = Mexico::FileSystem::PropertyMap.new
  end

  if properties.nil?
    properties = ::Mexico::FileSystem::PropertyMap.new(key: 'layerProperties')
  end

end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



34
35
36
# File 'lib/mexico/file_system/layer.rb', line 34

def document
  @document
end

Instance Method Details

#add_property(prop) ⇒ Object



102
103
104
# File 'lib/mexico/file_system/layer.rb', line 102

def add_property(prop)
  properties.properties << prop
end

#after_parseObject

overrides method in ROXML callback after xml parsing process, to store this element in the document cache.



69
70
71
# File 'lib/mexico/file_system/layer.rb', line 69

def after_parse
  ::Mexico::FileSystem::FiestaDocument.store(self.identifier, self)
end

#identifier=(new_id) ⇒ Object



26
27
28
# File 'lib/mexico/file_system/layer.rb', line 26

def identifier=(new_id)
  @identifier = Mexico::Util::to_xml_id(new_id)
end

#itemsObject



62
63
64
# File 'lib/mexico/file_system/layer.rb', line 62

def items
  @document.items.select{|i| i.layers.include?(self) }
end

#items_form_a_forest?Boolean

Returns:

  • (Boolean)


85
86
87
88
89
90
91
92
93
94
# File 'lib/mexico/file_system/layer.rb', line 85

def items_form_a_forest?

  # I need precise semantics what kinds of item links
  # are supposed to model an actual parent-child-relationship.
  self.items.each do |item|
    puts "sources size for items %s: %i" % [item.identifier, item.sources.size]
    return false if item.sources.size > 1
  end
  return true
end

#items_form_an_edgeless_graph?Boolean

Returns:

  • (Boolean)


96
97
98
99
100
# File 'lib/mexico/file_system/layer.rb', line 96

def items_form_an_edgeless_graph?
  self.items.each do |item|
    return false if item.item_links.size > 1
  end
end

#predecessor_layersObject

returns all layers that are linked to this layer such that this layer is the target, and the result layer is the source.



75
76
77
# File 'lib/mexico/file_system/layer.rb', line 75

def predecessor_layers
  document.layer_connectors.select{|c| c.target==self}.collect{|c| [c.source, c.role]}
end

#successor_layersObject

returns all layers that are linked to this layer such that this layer is the source, and the result layer is the target.



81
82
83
# File 'lib/mexico/file_system/layer.rb', line 81

def successor_layers
  document.layer_connectors.select{|c| c.source==self}.collect{|c| [c.target, c.role]}
end