summaryrefslogtreecommitdiff
path: root/lib/feature.rb
blob: 8b0839f8cc5ac3fd8840afc9805753bd127f20b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module OpenTox

	# uri: /feature/:name/:property_name/:property_value/...
	class Feature < OpenTox

		attr_accessor :name, :values

		def initialize(params)
			if params[:uri]
				@uri = params[:uri]
				items = URI.split(@uri)[5].split(/\//)
				@name = items[2]
				@values = {}
				i = 4
				while i < items.size
					@values[items[i]] = items[i+1]
					i += 2
				end
			else 
				@name = params[:name]
				#@name = URI.encode(URI.decode(params[:name]))
				@values = params[:values]
				@uri = File.join(@@config[:services]["opentox-dataset"],"feature",path)
			end
		end

		def values_path
			path = '' 
			@values.each do |k,v|
				path += '/' + URI.encode(k.to_s) + '/' + URI.encode(v.to_s)
			end
			path
		end

		def path
			File.join(@name,values_path)
		end

		def value(property)
			items = @uri.split(/\//)
			i = items.index(property)
			items[i+1]
		end

	end
end