Class: Lbp::Resource

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

Direct Known Subclasses

Expression, Manifestation, Transcription

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_id) ⇒ Resource

Returns a new instance of Resource.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/lbp/resource.rb', line 12

def initialize(resource_id)
	# fist conditions check to see if search results 
	# are being passed
	if resource_id.class != String
		@results = resource_id
		# resource should should be returned instead of "unsure"
		@resource_shortId = @results.first[:s].to_s.split("resource/").last
		@resource_url = @results.first[:s].to_s
		# if resource id is a string rather than results 
	# it looks ot see if this is a URL to query for results	
	elsif resource_id.include? "http"
		@query = Query.new();
		@results = @query.subject("<" + resource_id + ">")
		@resource_url = resource_id
		@resource_shortId = resource_id.split("resource/").last
	# finally, it looks for results using the shortId
	else
		@query = Query.new();
		@results = @query.subject_with_short_id(resource_id)
		@resource_url = "http://scta.info/resource/" + resource_id
		@resource_shortId = resource_id
	end
end

Instance Attribute Details

#resource_shortIdObject (readonly)

Returns the value of attribute resource_shortId.



11
12
13
# File 'lib/lbp/resource.rb', line 11

def resource_shortId
  @resource_shortId
end

#resource_urlObject (readonly)

Returns the value of attribute resource_url.



11
12
13
# File 'lib/lbp/resource.rb', line 11

def resource_url
  @resource_url
end

#resultsObject (readonly)

Returns the value of attribute results.



11
12
13
# File 'lib/lbp/resource.rb', line 11

def results
  @results
end

Instance Method Details

#convertObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/lbp/resource.rb', line 35

def convert
	#this conditional should be replaced 
	# by a function that converts the string
	# into a class name
	if self.type_shortId == 'workGroup'
		return WorkGroup.new(@results)
	elsif self.type_shortId == 'work'
		return Work.new(@results)
	elsif self.type_shortId == 'expression'
		return Expression.new(@results)
	elsif self.type_shortId == "manifestation"
		return Manifestation.new(@results)
	elsif self.type_shortId == "transcription"
		return Transcription.new(@results)
	else
		puts "no subclass to conver to"
		return self
	end
end

#structureTypeObject



68
69
70
# File 'lib/lbp/resource.rb', line 68

def structureType
	type = @results.dup.filter(:p => RDF::URI("http://scta.info/property/structureType")).first[:o].to_s
end

#structureType_shortIdObject

structure type should be moved to expression and other classes because it’s not generic enough some resources like quotes or name will not have structure type



65
66
67
# File 'lib/lbp/resource.rb', line 65

def structureType_shortId
	type = @results.dup.filter(:p => RDF::URI("http://scta.info/property/structureType")).first[:o].to_s.split("/").last
end

#titleObject



60
61
62
# File 'lib/lbp/resource.rb', line 60

def title
	type = @results.dup.filter(:p => RDF::URI(RDF::Vocab::DC11.title)).first[:o].to_s
end

#typeObject



57
58
59
# File 'lib/lbp/resource.rb', line 57

def type
	type = @results.dup.filter(:p => RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")).first[:o].to_s
end

#type_shortIdObject



54
55
56
# File 'lib/lbp/resource.rb', line 54

def type_shortId
	type = @results.dup.filter(:p => RDF::URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")).first[:o].to_s.split("/").last
end