Class: Mexico::FileSystem::Item

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

Overview

The basic data unit object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Item

Returns a new instance of Item.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/mexico/file_system/item.rb', line 65

def initialize(args={})
  args.each do |k,v|
    if self.respond_to?("#{k}=")
      send("#{k}=", v)
    end
  end
  @explicit_item_links = []
  @implicit_item_links = []
  @inverse_linked_items = []
  @layer_links = []
  @point_links = []
  @interval_links = []
end

Instance Attribute Details

#documentObject

Returns the value of attribute document.



48
49
50
# File 'lib/mexico/file_system/item.rb', line 48

def document
  @document
end

Returns the value of attribute implicit_item_links.



50
51
52
# File 'lib/mexico/file_system/item.rb', line 50

def implicit_item_links
  @implicit_item_links
end

Instance Method Details



130
131
132
# File 'lib/mexico/file_system/item.rb', line 130

def add_explicit_item_link(new_item_link)
  @explicit_item_links << new_item_link
end


134
135
136
# File 'lib/mexico/file_system/item.rb', line 134

def add_implicit_item_link(new_item_link)
  @implicit_item_links << new_item_link
end


143
144
145
# File 'lib/mexico/file_system/item.rb', line 143

def add_interval_link(new_interval_link)
  @interval_links << new_interval_link
end

#add_inverse_linked_item(item) ⇒ Object



104
105
106
# File 'lib/mexico/file_system/item.rb', line 104

def add_inverse_linked_item(item)
  @inverse_linked_items << item
end


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/mexico/file_system/item.rb', line 108

def add_item_link(new_item_link)
  # add the item link
  add_explicit_item_link(new_item_link)

  other_item = new_item_link.target_item

  # add an inverse item link for _every_ item link
  # this is for retrieving item links from the other direction
  other_item.add_inverse_linked_item(self)

  # if an inverse relation for the role exists,
  # puts Mexico::FileSystem::ItemLink::INVERSE_ROLES.has_key?(new_item_link.role)
  if Mexico::FileSystem::ItemLink::INVERSE_ROLES.has_key?(new_item_link.role)
    # add an implicit link for this inverse relation
    # puts new_item_link.target_item

    other_item.add_implicit_item_link Mexico::FileSystem::ImplicitItemLink.new(
                                          role: Mexico::FileSystem::ItemLink::INVERSE_ROLES[new_item_link.role],
                                          target_object: self, item: other_item )
  end
end


148
149
150
# File 'lib/mexico/file_system/item.rb', line 148

def add_layer_link(new_layer_link)
  @layer_links << new_layer_link
end


138
139
140
# File 'lib/mexico/file_system/item.rb', line 138

def add_point_link(new_point_link)
  @point_links << new_point_link
end

#after_parseObject

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.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/mexico/file_system/item.rb', line 82

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

  [item_links,layer_links,point_links,interval_links].flatten.each do |link|
    link.item = self

    if ::Mexico::FileSystem::FiestaDocument.knows?(link.target)
      link.target_object=::Mexico::FileSystem::FiestaDocument.resolve(link.target)
    else
      # store i in watch list
      ::Mexico::FileSystem::FiestaDocument.watch(link.target, link, :target_object=)
    end

  end

end

#identifier=(new_id) ⇒ Object



27
28
29
# File 'lib/mexico/file_system/item.rb', line 27

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


100
101
102
# File 'lib/mexico/file_system/item.rb', line 100

def item_links
  @explicit_item_links + @implicit_item_links
end

#layersObject



152
153
154
155
156
# File 'lib/mexico/file_system/item.rb', line 152

def layers
  #puts layer_links.collect{|l| l.target}.join
  #puts layer_links.collect{|l| l.target.class }.join
  layer_links.collect{|l| l.layer }
end

#sourcesObject

Retrieves all items that act as a source (or predecessor) in the item link graph.



160
161
162
# File 'lib/mexico/file_system/item.rb', line 160

def sources
  @inverse_linked_items
end

#targetsObject

Retrieves all items that act as a target (or successor) in the item link graph.



166
167
168
# File 'lib/mexico/file_system/item.rb', line 166

def targets
  item_links.collect{|l| l.target_object }
end