Class: PubliSci::Prov::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-publisci/metadata/prov/association.rb

Instance Method Summary collapse

Instance Method Details

#agent(agent = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bio-publisci/metadata/prov/association.rb', line 12

def agent(agent=nil)
  if agent
    # agent = Prov.agents[agent.to_sym] if agent.is_a?(String) || agent.is_a?(Symbol)
    # raise "UnkownAgent #{ag}" unless agent
    # puts "Warning: overwriting agent #{@agent.subject}" if @agent
    @agent = agent
  elsif @agent.is_a? Symbol
    @agent = Prov.agents[@agent]
  else
    @agent
  end
end

#had_plan(*args, &block) ⇒ Object Also known as: plan



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bio-publisci/metadata/prov/association.rb', line 25

def had_plan(*args, &block)
  if block_given?
    p = Prov::Plan.new
    p.instance_eval(&block)
    p.__label=args[0]
    @plan = p
    Prov.register(args[0], p)
  elsif args.size == 0
    if @plan.is_a? Symbol
      @plan = Prov.plans[@plan]
    end
    @plan
  elsif args.size == 1
    if args[0].is_a? Symbol
      raise "UnknownPlan: #{args[0]}" unless Prov.plans[args[0]]
      @plan = Prov.plans[args[0]]
    else
      @plan = args[0]
    end
  else
    name = args.shift
    args = Hash[*args]
    p = Prov::Plan.new

    p.__label=name
    p.subject args[:subject]
    (args.keys - [:subject]).map{|k|
      raise "Unkown plan setting #{k}" unless try_auto_set(p,k,args[k])
    }
    @plan = p
    Prov.register(name, p)
  end
end

#subject(sub = nil) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/bio-publisci/metadata/prov/association.rb', line 4

def subject(sub=nil)
  if sub
    @subject = sub
  else
    @subject ||= "#{Prov.base_url}/assoc/#{Time.now.nsec.to_s(32)}"
  end
end

#to_n3Object



60
61
62
63
64
65
66
# File 'lib/bio-publisci/metadata/prov/association.rb', line 60

def to_n3
  str = "<#{subject}> a prov:Association ;\n"
  str << "\tprov:agent <#{agent}> ;\n"
  str << "\tprov:hadPlan <#{plan}> ;\n" if plan
  str[-2] = ".\n"
  str
end

#to_sObject



68
69
70
# File 'lib/bio-publisci/metadata/prov/association.rb', line 68

def to_s
  subject
end