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



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

def self.find(id, ontology, params = {})
  ontology = HTTP.get(ontology, params)
  ontology.explore.class(URI.escape(id, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")))
end

.search(*args) ⇒ Object

Raises:

  • (ArgumentError)


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

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)


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

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)


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

def obsolete?
  self.obsolete
end

#prefLabel(options = {}) ⇒ Object



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

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



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

def purl
  return "" if self.links.nil?
  ont = self.explore.ontology
  "#{LinkedData::Client.settings.purl_prefix}/#{ont.acronym}?conceptid=#{URI.escape(self.id, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"
end

#relation_iconObject

TODO: Implement properly



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

def relation_icon; ""; end

#to_jsonldObject



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

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