Class: Reddy::URIRef
- Inherits:
-
Object
- Object
- Reddy::URIRef
- Defined in:
- lib/reddy/uriref.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #+(input) ⇒ Object
- #==(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.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/reddy/uriref.rb', line 11 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.
10 11 12 |
# File 'lib/reddy/uriref.rb', line 10 def uri @uri end |
Instance Method Details
#+(input) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/reddy/uriref.rb', line 22 def + (input) if input.class == String input_uri = Addressable::URI.parse(input) else input_uri = Addressable::URI.parse(input.to_s) end return URIRef.new((@uri + input_uri).to_s) end |
#==(other) ⇒ Object
41 42 43 |
# File 'lib/reddy/uriref.rb', line 41 def == (other) return true if @uri == other.uri end |
#load_graph ⇒ Object
61 62 63 64 |
# File 'lib/reddy/uriref.rb', line 61 def load_graph get = Net::HTTP.start(@uri.host, @uri.port) {|http| [:xml, http.get(@uri.path)] } return Reddy::RdfXmlParser.new(get[1].body, @uri.to_s).graph if get[0] == :xml end |
#short_name ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/reddy/uriref.rb', line 31 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
53 54 55 56 57 58 59 |
# File 'lib/reddy/uriref.rb', line 53 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
49 50 51 |
# File 'lib/reddy/uriref.rb', line 49 def to_ntriples "<" + @uri.to_s + ">" end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/reddy/uriref.rb', line 45 def to_s @uri.to_s end |