Sha256: bc199d322b8943e36f730256c0253feb1d922ce8a077dbfc6a18b59cd6131c7a

Contents?: true

Size: 1.55 KB

Versions: 8

Compression:

Stored size: 1.55 KB

Contents

module PubliSci
  class Prov
    class Usage
      include Prov::Element

      def __label
        @__label ||= Time.now.nsec.to_s(32)
      end

      def entity(entity=nil)
        basic_keyword(:entity,:entities,entity)
      end

      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
          unless (Prov.registry[:role]||={})[args[0]]
            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
      alias_method :role, :had_role

      def to_n3
        str = "<#{subject}> a prov:Usage ;\n"
        str << "\tprov:entity <#{entity}> ;\n"
        str << "\tprov:hadRole <#{had_role}> ;\n" if had_role
        str[-2] = ".\n"
        str
      end

      def to_s
        subject
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
publisci-0.1.6 lib/publisci/metadata/prov/usage.rb
publisci-0.1.5 lib/publisci/metadata/prov/usage.rb
publisci-0.1.4 lib/publisci/metadata/prov/usage.rb
publisci-0.1.3 lib/publisci/metadata/prov/usage.rb
publisci-0.1.2 lib/bio-publisci/metadata/prov/usage.rb
bio-publisci-0.1.0 lib/bio-publisci/metadata/prov/usage.rb
bio-publisci-0.0.8 lib/bio-publisci/metadata/prov/usage.rb
bio-publisci-0.0.7 lib/bio-publisci/metadata/prov/usage.rb