Class: Mexico::FileSystem::FiestaDocument
- Inherits:
-
Object
- Object
- Mexico::FileSystem::FiestaDocument
- Extended by:
- Util::FancyContainer
- Includes:
- Poseidon, ROXML
- Defined in:
- lib/mexico/file_system/fiesta_document.rb
Overview
FiESTA Document
Constant Summary collapse
- @@CACHE =
{}
Instance Attribute Summary collapse
-
#resource ⇒ Object
Returns the value of attribute resource.
Class Method Summary collapse
-
.check_watch(needed_id, needed_object) ⇒ void
Checks whether the given id/object pair is watched, and takes appropriate action if this is the case.
-
.knows?(xml_id) ⇒ Boolean
Retrieves a stored object from the temporary import cache.
-
.open(filename) ⇒ Mexico::FileSystem::FiestaDocument
Opens the document at the given location.
-
.resolve(xml_id) ⇒ Object
Retrieves a stored object from the temporary import cache.
-
.store(xml_id, ruby_object) ⇒ void
Retrieves a stored object from the temporary import cache.
-
.watch(needed_id, object, method) ⇒ Object
Put an xml id into the watch list, along with an object and a method.
Instance Method Summary collapse
- #add_item(item = nil) ⇒ Object
- #add_layer(args) ⇒ Object
- #add_layer_connector(layer_connector) ⇒ Object
-
#add_standard_timeline(unit = "ms") ⇒ Scale
Adds a standard timeline scale to the document.
-
#after_parse ⇒ Object
This method attempts to link objects from other locations of the XML/object tree into position inside this object, by following the xml ids given in the appropriate fields of this class.
- #get_layer_by_id(id) ⇒ Object
- #identifier=(new_id) ⇒ Object
-
#initialize ⇒ FiestaDocument
constructor
Creates a new, empty instance of a FiESTA document.
- #inter_layer_graph(layer1, layer2) ⇒ Object
- #inter_layer_graph_list ⇒ Object
-
#inter_layer_sink_cardinality ⇒ Object
Cardinality of source elements: how many links are connected to the source nodes?.
-
#inter_layer_source_cardinality ⇒ Object
Cardinality of source elements: how many links are connected to the source nodes?.
- #layers_form_a_cdag? ⇒ Boolean
- #layers_form_a_dag? ⇒ Boolean
- #layers_form_a_forest? ⇒ Boolean
- #layers_form_a_graph? ⇒ Boolean
- #layers_form_a_tree? ⇒ Boolean
- #layers_form_an_edgeless_graph? ⇒ Boolean
- #layers_form_an_empty_graph? ⇒ Boolean
- #link_document ⇒ Object
- #sink_cardinality_for_layer(layer1, layer2) ⇒ Object
- #source_cardinality_for_layer(layer1, layer2) ⇒ Object
Methods included from Util::FancyContainer
Constructor Details
#initialize ⇒ FiestaDocument
Check if all standard or default values are set correctly.
Creates a new, empty instance of a FiESTA document.
133 134 135 136 137 138 139 140 141 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 133 def initialize super @head = Mexico::FileSystem::Head.new @scales_container = [] @layers_container = [] @layer_connectors = [] @items_container = [] link_document end |
Instance Attribute Details
#resource ⇒ Object
Returns the value of attribute resource.
58 59 60 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 58 def resource @resource end |
Class Method Details
.check_watch(needed_id, needed_object) ⇒ void
This method returns an undefined value.
Checks whether the given id/object pair is watched, and takes appropriate action if this is the case.
113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 113 def self.check_watch(needed_id, needed_object) if defined?(@@WATCHLIST) if @@WATCHLIST.has_key?("#{Thread.current.__id__}.#{needed_id}") @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"].each do |entry| entry[0].send(entry[1], needed_object) end @@WATCHLIST.delete("#{Thread.current.__id__}.#{needed_id}") end end end |
.knows?(xml_id) ⇒ Boolean
Retrieves a stored object from the temporary import cache.
87 88 89 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 87 def self.knows?(xml_id) @@CACHE.has_key?("#{Thread.current.__id__}.#{xml_id}") end |
.open(filename) ⇒ Mexico::FileSystem::FiestaDocument
Opens the document at the given location.
127 128 129 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 127 def self.open(filename) self.from_xml(File.open(filename)) end |
.resolve(xml_id) ⇒ Object
Retrieves a stored object from the temporary import cache.
80 81 82 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 80 def self.resolve(xml_id) @@CACHE["#{Thread.current.__id__}.#{xml_id}"] end |
.store(xml_id, ruby_object) ⇒ void
This method returns an undefined value.
Retrieves a stored object from the temporary import cache.
95 96 97 98 99 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 95 def self.store(xml_id, ruby_object) @@CACHE = {} unless defined?(@@CACHE) @@CACHE["#{Thread.current.__id__}.#{xml_id}"] = ruby_object ::Mexico::FileSystem::FiestaDocument.check_watch(xml_id, ruby_object) end |
.watch(needed_id, object, method) ⇒ Object
Put an xml id into the watch list, along with an object and a method
102 103 104 105 106 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 102 def self.watch(needed_id, object, method) @@WATCHLIST = {} unless defined?(@@WATCHLIST) @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"] = [] unless @@WATCHLIST.has_key?("#{Thread.current.__id__}.#{needed_id}") @@WATCHLIST["#{Thread.current.__id__}.#{needed_id}"] << [object, method] end |
Instance Method Details
#add_item(item = nil) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 200 def add_item(item=nil) if item.nil? new_item = Mexico::FileSystem::Item.new(identifier: "item#{rand(2**16)}") # @TODO check if that random ID is still available! end if item.is_a?(Hash) new_item = Mexico::FileSystem::Item.new(item.merge({document: self})) end if item.is_a?(Mexico::FileSystem::Item) new_item = item end # @TODO catch error if parameter has wrong object type if block_given? yield new_item end # check if item is not in the array already @items_container << new_item new_item end |
#add_layer(args) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 152 def add_layer(args) if args.is_a?(Hash) new_layer = Mexico::FileSystem::Layer.new(args.merge({document: self})) @layers_container << new_layer return new_layer end if args.is_a?(Mexico::FileSystem::Layer) @layers_container << args return args end # @TODO catch error if parameter has wrong object type return nil end |
#add_layer_connector(layer_connector) ⇒ Object
220 221 222 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 220 def add_layer_connector(layer_connector) @layer_connectors << layer_connector end |
#add_standard_timeline(unit = "ms") ⇒ Scale
Adds a standard timeline scale to the document.
146 147 148 149 150 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 146 def add_standard_timeline(unit="ms") @scales_container << Mexico::FileSystem::Scale.new(identifier: 'timeline01', name: 'Timeline', unit: unit, dimension: Mexico::FileSystem::Scale::DIM_TIME) @scales_container.last.document = self @scales_container.last end |
#after_parse ⇒ Object
This method attempts to link objects from other locations of the XML/object tree into position inside this object, by following the xml ids given in the appropriate fields of this class.
169 170 171 172 173 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 169 def after_parse link_document # then clear cache @@CACHE.clear end |
#get_layer_by_id(id) ⇒ Object
224 225 226 227 228 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 224 def get_layer_by_id(id) matches = layers.select{|l| l.identifier == id} return matches[0] if matches.size>0 return nil end |
#identifier=(new_id) ⇒ Object
344 345 346 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 344 def identifier=(new_id) @identifier = Mexico::Util::to_xml_id(new_id) end |
#inter_layer_graph(layer1, layer2) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 268 def inter_layer_graph(layer1, layer2) # 0: source items, 1: target items, 2: links result_graph = { sources: Set.new, sinks: Set.new, links: Set.new, source_map: Hash.new, sink_map: Hash.new } result_graph[:sources].merge layer1.items result_graph[:sinks].merge layer2.items links = result_graph[:sources].collect{|i| i.item_links }.flatten links = links.select{|l| l.target_object.layers.include?(layer2) } result_graph[:links] = links # fill the source and target maps with data result_graph[:sources].each do |node| result_graph[:source_map][node] = Set.new end result_graph[:sinks].each do |node| result_graph[:sink_map][node] = Set.new end result_graph[:links].each do |link| source = link.item sink = link.target_item result_graph[:source_map][source] << sink result_graph[:sink_map][sink] << source end result_graph end |
#inter_layer_graph_list ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 303 def inter_layer_graph_list # collect all parent child pairs of layers # calculate layer graphs for all of them ilg_list = Hash.new layers.each do |parent_layer| parent_layer.successor_layers.each do |child_layer| ilg_list[ [parent_layer, child_layer[0]] ] = inter_layer_graph(parent_layer, child_layer[0]) end end ilg_list end |
#inter_layer_sink_cardinality ⇒ Object
Cardinality of source elements: how many links are connected to the source nodes?
335 336 337 338 339 340 341 342 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 335 def inter_layer_sink_cardinality card = 0 inter_layer_graph_list.each do |k,v| graph_card = v[:source_map].values.collect{|m| m.size}.max card = [card,graph_card].max end card end |
#inter_layer_source_cardinality ⇒ Object
Cardinality of source elements: how many links are connected to the source nodes?
325 326 327 328 329 330 331 332 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 325 def inter_layer_source_cardinality card = 0 inter_layer_graph_list.each do |k,v| graph_card = v[:sink_map].values.collect{|m| m.size}.max card = [card,graph_card].max end card end |
#layers_form_a_cdag? ⇒ Boolean
238 239 240 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 238 def layers_form_a_cdag? raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.') end |
#layers_form_a_dag? ⇒ Boolean
234 235 236 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 234 def layers_form_a_dag? raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.') end |
#layers_form_a_forest? ⇒ Boolean
242 243 244 245 246 247 248 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 242 def layers_form_a_forest? # check whether all layers have at most one parent layer self.layers.each do |layer| return false if layer.predecessor_layers.size > 1 end return true end |
#layers_form_a_graph? ⇒ Boolean
230 231 232 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 230 def layers_form_a_graph? true end |
#layers_form_a_tree? ⇒ Boolean
250 251 252 253 254 255 256 257 258 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 250 def layers_form_a_tree? # check whether all layers but one have exactly one parent layer other_than_ones = [] self.layers.each do |layer| s = layer.predecessor_layers.size other_than_ones << s if s != 1 end true if s.size == 1 && s.first==0 end |
#layers_form_an_edgeless_graph? ⇒ Boolean
260 261 262 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 260 def layers_form_an_edgeless_graph? @layer_connectors.empty? end |
#layers_form_an_empty_graph? ⇒ Boolean
264 265 266 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 264 def layers_form_an_empty_graph? layers.empty? end |
#link_document ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 175 def link_document # process xml ids scales.each do |x| x.document = self end layers.each do |x| x.document = self end items.each do |x| x.document = self x.item_links.each do |y| y.document = self end x.layer_links.each do |y| y.document = self end x.point_links.each do |y| y.document = self end x.interval_links.each do |y| y.document = self end end end |
#sink_cardinality_for_layer(layer1, layer2) ⇒ Object
319 320 321 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 319 def sink_cardinality_for_layer(layer1, layer2) inter_layer_graph_list[[layer1,layer2]][:source_map].values.collect{|m| m.size}.max end |
#source_cardinality_for_layer(layer1, layer2) ⇒ Object
315 316 317 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 315 def source_cardinality_for_layer(layer1, layer2) inter_layer_graph_list[[layer1,layer2]][:sink_map].values.collect{|m| m.size}.max end |