Sha256: a65dea47ba33dc65d796e5905e58e216f1f9c38d6ad3b3926731a603762c79b9

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

module PubliSci
class Prov
  class Activity
    include Prov::Element
    class Associations < Array
      include PubliSci::Prov::Dereferencable
      def method
        :agents
      end
    end

    class Generations < Array
      include PubliSci::Prov::Dereferencable
      def method
        :entities
      end
    end

    class Usages < Array
      include PubliSci::Prov::Dereferencable
      def method
        :entities
      end
    end

    def generated(entity=nil)
      if entity.is_a? Entity
        entity.generated_by self
      elsif Prov.entities[entity]
        Prov.entities[entity].generated_by self
      end
      basic_list(:generated,:entities,Generations,entity)
    end

    def associated_with(agent=nil, &block)
      block_list(:associated,:associations,Association,Associations,agent,&block)
    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.dereference.map{|src|
          str << "<#{src}>, "
        }
        str[-2]=" "
        str[-1]=";\n"
      end

      if 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
        }
      end

      if associated_with
        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"
          end
        }
      end

      add_custom(str)

      str << "\trdfs:label \"#{__label}\" .\n\n"
    end

    def to_s
      subject
    end
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bio-publisci-0.0.7 lib/bio-publisci/metadata/prov/activity.rb