Class: PubliSci::Prov::Association

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

Instance Method Summary collapse

Methods included from Element

#__label=, #subject, #subject=, #subject_id

Methods included from CustomPredicate

#add_custom, #custom, #has

Methods included from Vocabulary

#vocabulary

Instance Method Details

#__labelObject



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

def __label
  # raise "MissingInternalLabel: no __label for #{self.inspect}" unless @__label
  @__label ||= Time.now.nsec.to_s(32)
end

#agent(agent = nil) ⇒ Object



12
13
14
# File 'lib/bio-publisci/metadata/prov/association.rb', line 12

def agent(agent=nil)
  basic_keyword(:agent,:agents,agent)
end

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



16
17
18
19
20
21
22
23
24
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
# File 'lib/bio-publisci/metadata/prov/association.rb', line 16

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
      raise "UnknownPlan: #{@plan}" unless Prov.plans[@plan]
      @plan = Prov.plans[@plan]
    end
    @plan
  elsif args.size == 1
    if Prov.plans[args[0]]
      @plan = args[0]
    else
      p = Prov::Plan.new
      p.__label=args[0]
      @plan = p
      Prov.register(args[0], p)
    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

#had_role(*args, &block) ⇒ Object Also known as: role



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/bio-publisci/metadata/prov/association.rb', line 54

def had_role(*args, &block)
  if block_given?
    p = Prov::Role.new
    p.instance_eval(&block)
    p.__label=args[0]
    @role = p
    # puts p.class
    Prov.register(args[0], p)
  elsif args.size == 0
    if @role.is_a? Symbol
      raise "UnknownRole: #{@role}" unless (Prov.registry[:role]||={})[@role]
      @role = Prov.registry[:role][@role]
    end
    @role
  elsif args.size == 1
    if (Prov.registry[:role]||={})[args[0]]
      @role = args[0]
    else
      p = Prov::Role.new
      p.__label=args[0]
      @role = p
      Prov.register(args[0], p)
    end
  else
    name = args.shift
    args = Hash[*args]
    p = Prov::Role.new

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

#to_n3Object



93
94
95
96
97
98
99
100
# File 'lib/bio-publisci/metadata/prov/association.rb', line 93

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

#to_sObject



102
103
104
# File 'lib/bio-publisci/metadata/prov/association.rb', line 102

def to_s
  subject
end