Class: Rena::URIRef
- Inherits:
-
Object
- Object
- Rena::URIRef
- Defined in:
- lib/rena/uriref.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(string) ⇒ URIRef
constructor
A new instance of URIRef.
- #load_graph ⇒ Object
- #short_name ⇒ Object
- #test_string(string) ⇒ Object
- #to_ntriples ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(string) ⇒ URIRef
Returns a new instance of URIRef.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rena/uriref.rb', line 9 def initialize (string) self.test_string(string) @uri = Addressable::URI.parse(string) if @uri.relative? raise UriRelativeException, "<" + @uri.to_s + ">" end if !@uri.to_s.match(/^javascript/).nil? raise "Javascript pseudo-URIs are not acceptable" end end |
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
8 9 10 |
# File 'lib/rena/uriref.rb', line 8 def uri @uri end |
Instance Method Details
#==(other) ⇒ Object
30 31 32 |
# File 'lib/rena/uriref.rb', line 30 def == (other) return true if @uri == other.uri end |
#load_graph ⇒ Object
50 51 52 53 |
# File 'lib/rena/uriref.rb', line 50 def load_graph get = Net::HTTP.start(@uri.host, @uri.port) {|http| [:xml, http.get(@uri.path)] } return Rena::RdfXmlParser.new(get[1].body, @uri.to_s).graph if get[0] == :xml end |
#short_name ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/rena/uriref.rb', line 20 def short_name if @uri.fragment() return @uri.fragment() elsif @uri.path.split("/").last.class == String and @uri.path.split("/").last.length > 0 return @uri.path.split("/").last else return false end end |
#test_string(string) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/rena/uriref.rb', line 42 def test_string (string) string.to_s.each_byte do |b| if b >= 0 and b <= 31 raise "URI must not contain control characters" end end end |
#to_ntriples ⇒ Object
38 39 40 |
# File 'lib/rena/uriref.rb', line 38 def to_ntriples "<" + @uri.to_s + ">" end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/rena/uriref.rb', line 34 def to_s @uri.to_s end |