lib/bio-publisci/metadata/prov/activity.rb in bio-publisci-0.0.5 vs lib/bio-publisci/metadata/prov/activity.rb in bio-publisci-0.0.6
- old
+ new
@@ -1,90 +1,69 @@
module PubliSci
module Prov
class Activity
include Prov::Element
class Associations < Array
- def [](index)
- if self.fetch(index).is_a? Symbol
- Prov.agents[self.fetch(index)]
- else
- self.fetch(index)
- end
+ include PubliSci::Prov::Dereferencable
+ def method
+ :agents
end
end
- def generated(entity=nil)
- if entity
- # if entity.is_a? Symbol
- # entity = Prov.entities[entity.to_sym]
- # end
+ class Generations < Array
+ include PubliSci::Prov::Dereferencable
+ def method
+ :entities
+ end
+ end
- if entity.is_a? Entity
- entity.generated_by self
- end
-
- (@generated ||= []) << entity
- elsif @generated.is_a? Symbol
- @generated = Prov.entities[@generated]
- else
- @generated
+ class Usages < Array
+ include PubliSci::Prov::Dereferencable
+ def method
+ :entities
end
end
- def generated=(gen)
- @generated = gen
+ def generated(entity=nil)
+ if entity.is_a? Entity
+ entity.generated_by self
+ end
+ basic_list(:generated,:entities,Generations,entity)
end
def associated_with(agent=nil, &block)
- if agent
- (@associated ||= Associations.new) << agent
- # Prov.register(nil,assoc)
- elsif block_given?
- assoc = Association.new
- assoc.instance_eval(&block)
- (@associated ||= Associations.new) << assoc
- Prov.register(nil,assoc)
- else
- @associated
- end
+ block_list(:associated,:associations,Association,Associations,agent,&block)
end
- def used(entity=nil)
- if entity
- (@used ||= []) << entity
- elsif @used
- @used.map{|u| u.is_a?(Symbol) ? Prov.entities[u] : u}
- else
- @used
- end
+ def used(entity=nil, &block)
+ block_list(:use,:usages,Usage,Usages,entity, &block)
end
def to_n3
str = "<#{subject}> a prov:Activity ;\n"
if generated
str << "\tprov:generated "
- generated.map{|src|
- src = Prov.entities[src] if src.is_a?(Symbol) && Prov.entities[src]
+ generated.dereference.map{|src|
str << "<#{src}>, "
}
str[-2]=" "
str[-1]=";\n"
end
if used
- str << "\tprov:used "
- used.map{|used|
- str << "<#{used}>, "
+ used.dereference.map{|u|
+ if u.is_a? Usage
+ str << "\tprov:used <#{u.entity}> ;\n"
+ str << "\tprov:qualifiedUsage <#{u}> ;\n"
+ else
+ str << "\tprov:used <#{u}> ;\n"
+ end
}
- str[-2]=";"
- str[-1]="\n"
end
if associated_with
- associated_with.map{|assoc|
- assoc = Prov.agents[assoc] if assoc.is_a?(Symbol) && Prov.agents[assoc]
-
+ associated_with.dereference.map{|assoc|
if assoc.is_a? Association
str << "\tprov:wasAssociatedWith <#{assoc.agent}> ;\n"
str << "\tprov:qualifiedAssociation <#{assoc}> ;\n"
else
str << "\tprov:wasAssociatedWith <#{assoc}> ;\n"
\ No newline at end of file