Class: Lbp::ResourceIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/lbp/resource_identifier.rb

Overview

NOTE #rdf_uri can be a littel confusing, since it also works for RDF::Literal

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rdf_uri) ⇒ ResourceIdentifier

Returns a new instance of ResourceIdentifier.



20
21
22
23
24
25
26
27
28
# File 'lib/lbp/resource_identifier.rb', line 20

def initialize(rdf_uri)
	@rdf_uri = rdf_uri
	@url = rdf_uri.to_s
	@short_id = if @url.include? "property/"
		@url.split("property/").last
	else
		@url.split("resource/").last
	end
end

Instance Attribute Details

#rdf_uriObject (readonly)

Returns the value of attribute rdf_uri.



7
8
9
# File 'lib/lbp/resource_identifier.rb', line 7

def rdf_uri
  @rdf_uri
end

#short_idObject (readonly)

Returns the value of attribute short_id.



7
8
9
# File 'lib/lbp/resource_identifier.rb', line 7

def short_id
  @short_id
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/lbp/resource_identifier.rb', line 7

def url
  @url
end

Class Method Details

.from_rdf_uri(rdf_uri) ⇒ Object



15
16
17
# File 'lib/lbp/resource_identifier.rb', line 15

def from_rdf_uri(rdf_uri)
	rdf_uri
end

.from_short(short) ⇒ Object



9
10
11
# File 'lib/lbp/resource_identifier.rb', line 9

def from_short(short)
	RDF::URI.new("http://scta.info/resource/#{short}")
end

.from_url(url) ⇒ Object



12
13
14
# File 'lib/lbp/resource_identifier.rb', line 12

def from_url(url)
	RDF::URI.new(url)
end

Instance Method Details

#resourceObject



32
33
34
35
36
37
38
# File 'lib/lbp/resource_identifier.rb', line 32

def resource
	unless @rdf_uri.class == RDF::Literal
		Lbp::Resource.find(url)
	else 
		nil
	end
end

#to_sObject



29
30
31
# File 'lib/lbp/resource_identifier.rb', line 29

def to_s
	@url
end