Class: OrderedSet

Inherits:
Object
  • Object
show all
Defined in:
lib/active_rdf/objectmanager/ordered_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ OrderedSet

Initialize SeqContainer



11
12
13
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 11

def initialize(uri)
  @uri = RDF::Seq.new uri
end

Instance Attribute Details

#uriObject (readonly)

the uri of current resource



8
9
10
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 8

def uri
  @uri
end

Instance Method Details

#add(object) ⇒ Object

add a new object

  • object: RDFS::Resource



57
58
59
60
61
62
63
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 57

def add(object)
  # get predicate for next item
  predicate =  index_to_predicate(size + 1)
    
  # add item
  FederationManager.add(self.uri, predicate , object)
end

#at(index) ⇒ Object

get element at position index *index: int

return value: RDFS::Resource



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 27

def at(index)
  # get predicate for next item
  predicate =  index_to_predicate(index)
  
  # execute query
  result = Query.new.select(:o).where(self.uri, predicate, :o).execute
  
  if (!(result.nil?) and (result.size > 0))
    result.first
  else
    nil
  end
end

#delete(index) ⇒ Object

remove an existing object

  • index: int



67
68
69
70
71
72
73
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 67

def delete(index)
  # get predicate to delete
  predicate = index_to_predicate(index)
  
  # delete item
  FederationManager.delete(self.uri, predicate, nil)
end

#delete_allObject

remove all copy of object to OrderedSet



76
77
78
79
80
81
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 76

def delete_all()
  # call delete method
  (1..size).each do |index|
    self.delete(index)
  end
end

#elementsObject

get all elements of Resource that match with ‘rdf:_’

return value: Array



18
19
20
21
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 18

def elements
  # execute query
  query.collect { |predicate, object| object }
end

#replace(index, object) ⇒ Object

replace item

  • index: int

  • object: RDFS::Resource



86
87
88
89
90
91
92
93
94
95
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 86

def replace(index, object)
  # delete item
  self.delete(index)
    
  # get predicate for index
  predicate =  index_to_predicate(index)
    
  # add item
  FederationManager.add(self.uri, predicate , object)
end

#sizeObject

return size of elements

return value: int



44
45
46
47
48
49
50
51
52
53
# File 'lib/active_rdf/objectmanager/ordered_set.rb', line 44

def size
  result = query
  
  if result.empty?
    return 0
  else
    index = predicate_to_index result.last[0]
    return index.to_i
  end
end