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

Inherits:
Base
  • Object
show all
Defined in:
lib/ontologies_api_client/models/class.rb

Constant Summary collapse

HTTP =
LinkedData::Client::HTTP

Instance Attribute Summary

Attributes inherited from Base

#context, #instance_values, #links

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, attributes, class_for_type, #explore, #id, #initialize, #marshal_dump, #marshal_load, #method_missing, #respond_to?, #to_hash, #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(id, ontology, params = {}) ⇒ Object



47
48
49
50
# File 'lib/ontologies_api_client/models/class.rb', line 47

def self.find(id, ontology, params = {})
  ontology = HTTP.get(ontology, params)
  ontology.explore.class(CGI.escape(id))
end

.search(*args) ⇒ Object

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
# File 'lib/ontologies_api_client/models/class.rb', line 52

def self.search(*args)
  query = args.shift
  params = args.shift || {}
  params[:q] = query
  raise ArgumentError, "You must provide a search query: Class.search(query: 'melanoma')" if query.nil? || !query.is_a?(String)
  HTTP.post("/search", params)
end

Instance Method Details

#expanded?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/ontologies_api_client/models/class.rb', line 60

def expanded?
  !self.children.nil? && self.children.length > 0
end

#obsolete?Boolean

triple store predicate is <www.w3.org/2002/07/owl#deprecated>

Returns:

  • (Boolean)


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

def obsolete?
  self.obsolete
end

#prefLabel(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ontologies_api_client/models/class.rb', line 22

def prefLabel(options = {})
  if options[:use_html]
    if self.obsolete
      return "<span class='obsolete_class' title='obsolete class'>#{@prefLabel}</span>"
    else
      return "<span class='prefLabel'>#{@prefLabel}</span>"
    end
  else
    return @prefLabel
  end
end

#purlObject



41
42
43
44
45
# File 'lib/ontologies_api_client/models/class.rb', line 41

def purl
  return "" if self.links.nil?
  ont = self.explore.ontology
  "#{LinkedData::Client.settings.purl_prefix}/#{ont.acronym}/#{CGI.escape(self.id)}"
end

#relation_iconObject

TODO: Implement properly



35
# File 'lib/ontologies_api_client/models/class.rb', line 35

def relation_icon; ""; end

#to_jsonldObject



37
38
39
# File 'lib/ontologies_api_client/models/class.rb', line 37

def to_jsonld
  HTTP.get(self.links["self"], {}, {raw: true})
end