Class: LinkedData::Client::Models::Ontology

Inherits:
Base
  • Object
show all
Includes:
Collection, ReadWrite
Defined in:
lib/ontologies_api_client/models/ontology.rb

Constant Summary

Constants included from ReadWrite

ReadWrite::HTTP

Constants inherited from Base

Base::HTTP

Instance Attribute Summary

Attributes inherited from Base

#context, #instance_values, #links

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ReadWrite

#changed_values, #delete, #save, #update, #update_from_params

Methods included from Collection

included

Methods inherited from Base

#[], #[]=, attributes, class_for_type, #explore, #id, #initialize, #marshal_dump, #marshal_load, #method_missing, #respond_to?, #to_hash, #to_jsonld, #type

Constructor Details

This class inherits a constructor from LinkedData::Client::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class LinkedData::Client::Base

Class Method Details

.find_by(attrs, *args) ⇒ Object

Find a resource by a combination of attributes Override to search for views as well by default Views get hidden on the REST service unless the ‘include_views` parameter is set to `true`



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ontologies_api_client/models/ontology.rb', line 71

def self.find_by(attrs, *args)
  params = args.shift
  if params.is_a?(Hash)
    params[:include_views] = params[:include_views] || true
  else
    # Stick params back and create a new one
    args.push({include_views: true})
  end
  args.unshift(params)
  super(attrs, *args)
end

Instance Method Details

#acl_selectObject

For use with select lists, always includes the admin by default



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ontologies_api_client/models/ontology.rb', line 49

def acl_select
  select_opts = []
  return select_opts if self.acl.nil? or self.acl.empty?

  if self.acl.nil? || self.acl.empty?
    self.administeredBy.each do |userId|
      select_opts << [User.get(userId).username, userId]
    end
  else
    self.acl.each do |userId|
      select_opts << [User.get(userId).username, userId]
    end
  end

  (select_opts + self.administeredBy).uniq
end

#admin?(user) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/ontologies_api_client/models/ontology.rb', line 42

def admin?(user)
  return false if user.nil?
  return true if user.admin?
  return administeredBy.any? {|u| u == user.id}
end

#find(id, params = {}) ⇒ Object

Find a resource by id Override to search for views as well by default Views get hidden on the REST service unless the ‘include_views` parameter is set to `true`



88
89
90
91
# File 'lib/ontologies_api_client/models/ontology.rb', line 88

def find(id, params = {})
  params[:include_views] = params[:include_views] || true
  super(id, params)
end

#flat?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ontologies_api_client/models/ontology.rb', line 14

def flat?
  self.flat
end

#licensed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ontologies_api_client/models/ontology.rb', line 22

def licensed?
  viewingRestriction && viewingRestriction.downcase.eql?("licensed")
end

#private?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ontologies_api_client/models/ontology.rb', line 18

def private?
  viewingRestriction && viewingRestriction.downcase.eql?("private")
end

#purlObject



34
35
36
37
38
39
40
# File 'lib/ontologies_api_client/models/ontology.rb', line 34

def purl
  if self.acronym
    "#{LinkedData::Client.settings.purl_prefix}/#{acronym}"
  else
    ""
  end
end

#view?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ontologies_api_client/models/ontology.rb', line 30

def view?
  viewOf && viewOf.length > 1
end

#viewing_restricted?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ontologies_api_client/models/ontology.rb', line 26

def viewing_restricted?
  private? && licensed?
end