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_scale(args) ⇒ 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
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 214 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
234 235 236 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 234 def add_layer_connector(layer_connector) @layer_connectors << layer_connector end |
#add_scale(args) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 166 def add_scale(args) if args.is_a?(Hash) new_layer = Mexico::FileSystem::Scale.new(args.merge({document: self})) @scales_container << new_layer return new_layer end if args.is_a?(Mexico::FileSystem::Scale) @scales_container << args return args end # @TODO catch error if parameter has wrong object type return nil 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.
183 184 185 186 187 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 183 def after_parse link_document # then clear cache @@CACHE.clear end |
#get_layer_by_id(id) ⇒ Object
238 239 240 241 242 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 238 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
358 359 360 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 358 def identifier=(new_id) @identifier = Mexico::Util::to_xml_id(new_id) end |
#inter_layer_graph(layer1, layer2) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 282 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
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 317 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?
349 350 351 352 353 354 355 356 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 349 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?
339 340 341 342 343 344 345 346 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 339 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
252 253 254 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 252 def layers_form_a_cdag? raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.') end |
#layers_form_a_dag? ⇒ Boolean
248 249 250 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 248 def layers_form_a_dag? raise Mexico::NotYetImplementedError.new('This method has not been implemented yet.') end |
#layers_form_a_forest? ⇒ Boolean
256 257 258 259 260 261 262 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 256 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
244 245 246 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 244 def layers_form_a_graph? true end |
#layers_form_a_tree? ⇒ Boolean
264 265 266 267 268 269 270 271 272 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 264 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
274 275 276 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 274 def layers_form_an_edgeless_graph? @layer_connectors.empty? end |
#layers_form_an_empty_graph? ⇒ Boolean
278 279 280 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 278 def layers_form_an_empty_graph? layers.empty? end |
#link_document ⇒ Object
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 189 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
333 334 335 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 333 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
329 330 331 |
# File 'lib/mexico/file_system/fiesta_document.rb', line 329 def source_cardinality_for_layer(layer1, layer2) inter_layer_graph_list[[layer1,layer2]][:sink_map].values.collect{|m| m.size}.max end |