Class: PropertyList

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

Overview

Simple class which will contain all values of a specified property related to a subject. It provides some useful shortcut methods to work with properties and related values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Array

#extract_options!

Constructor Details

#initialize(p, pv_list, s, writeable = true) ⇒ PropertyList

Initialize a new list of properties’ values

  • p the original property

  • pv_list the list of properties’ values

  • s the sobject which property is related to

  • writeable if set to false, the list will be write-protected



15
16
17
18
19
# File 'lib/active_rdf/objectmanager/property_list.rb', line 15

def initialize(p, pv_list, s, writeable = true)
  super pv_list
  @s, @p = s, p
  @writeable = writeable
end

Instance Attribute Details

#pObject (readonly)

Add reader accessor



7
8
9
# File 'lib/active_rdf/objectmanager/property_list.rb', line 7

def p
  @p
end

#sObject (readonly)

Add reader accessor



7
8
9
# File 'lib/active_rdf/objectmanager/property_list.rb', line 7

def s
  @s
end

#writeableObject

Returns the value of attribute writeable.



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

def writeable
  @writeable
end

Instance Method Details

#<<(pv) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/active_rdf/objectmanager/property_list.rb', line 23

def <<(pv)
  check_writeable!
  # update the array list
  add pv
  
  # insert the new statment into the store
  ActiveRDF::FederationManager.add(@s, @p, pv)
end

#addObject

add a new property value realated to @p property and @s subject



22
# File 'lib/active_rdf/objectmanager/property_list.rb', line 22

alias :add :<<

#remove(*params) ⇒ Object

if no papameters will be specified, delete every triple related to :s and p: otherwise delete the triples whose values are specified by params



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/active_rdf/objectmanager/property_list.rb', line 47

def remove(*params)
  check_writeable!
  if params.length >= 1
    # delete only triples whose values is specified by parameters
    params.each{|param|
      if self.delete(param)
        return ActiveRDF::FederationManager.delete(@s, @p, param)
      end
    }
  else
    # delete every triple related to :s and :p whose values is contained by self...
    self.each{|value|
      if ActiveRDF::FederationManager.delete(@s, @p, value) == false
        return false
      end
    }
    # ...and clear the array Poperty_list array
    self.clear
    return true
  end
end

#replace(old_p_value, new_p_value) ⇒ Object

delete a statment which contains old_p_value and insert a new statment (@s, @p, new_p_value)



34
35
36
37
38
39
40
41
42
# File 'lib/active_rdf/objectmanager/property_list.rb', line 34

def replace(old_p_value, new_p_value)
  check_writeable!
  # delete the old statment
  self.delete(old_p_value)
  ActiveRDF::FederationManager.delete(@s, @p, old_p_value)
  
  # insert the new statment
  self << new_p_value
end