Class: YOWL::DocObject
- Inherits:
-
Object
- Object
- YOWL::DocObject
- Defined in:
- lib/yowl/util.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #escaped_short_name ⇒ Object
- #escaped_uri ⇒ Object
- #get_literal(property) ⇒ Object
- #hasOtherNamespace? ⇒ Boolean
- #hasUri?(uri_) ⇒ Boolean
-
#initialize(resource, schema) ⇒ DocObject
constructor
A new instance of DocObject.
- #ns ⇒ Object
- #ontology ⇒ Object
- #repository ⇒ Object
- #short_name ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(resource, schema) ⇒ DocObject
Returns a new instance of DocObject.
8 9 10 11 12 13 14 |
# File 'lib/yowl/util.rb', line 8 def initialize(resource, schema) @resource = resource @schema = schema if (@resource and not @resource.uri?) raise "ERROR: Instantiating an object with a non-URI resource: #{@resource.to_s} (#{@resource.inspect})" end end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
5 6 7 |
# File 'lib/yowl/util.rb', line 5 def resource @resource end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/yowl/util.rb', line 6 def schema @schema end |
Instance Method Details
#escaped_short_name ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/yowl/util.rb', line 65 def escaped_short_name() str = short_name() # TODO: optimize this into one pattern str = str.gsub("://", "_") str = str.gsub(".", "_") str = str.gsub(",", "_") str = str.gsub("/", "_") return str end |
#escaped_uri ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/yowl/util.rb', line 75 def escaped_uri() str = short_name().to_s # TODO: optimize this into one pattern str = str.gsub("://", "__") str = str.gsub(".", "_") str = str.gsub("/", "_") str = str.gsub("#", "_") str = str.gsub(":", "_") str = str.gsub(",", "_") return str end |
#get_literal(property) ⇒ Object
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/yowl/util.rb', line 91 def get_literal(property) if @resource.nil? return nil end value = @schema.model.first_value(RDF::Query::Pattern.new(@resource, property)) if not value return nil end return value.strip end |
#hasOtherNamespace? ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/yowl/util.rb', line 41 def hasOtherNamespace? schemaUri = @schema.uri case when schemaUri == ns return false when "#{schemaUri}#" == ns return false when "#{schemaUri}/" == ns return false end return true end |
#hasUri?(uri_) ⇒ Boolean
24 25 26 27 28 29 30 |
# File 'lib/yowl/util.rb', line 24 def hasUri?(uri_) case uri when String return uri == uri_ end return @resource == uri_ end |
#ns ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/yowl/util.rb', line 32 def ns() _uri = uri() lastChar = _uri[-1,1] if lastChar == '/' or lastChar == '#' return _uri end return _uri[0.._uri.rindex(/[#\/]/)] end |
#ontology ⇒ Object
102 103 104 |
# File 'lib/yowl/util.rb', line 102 def ontology return @schema.ontology ? @schema.ontology : nil end |
#repository ⇒ Object
16 17 18 |
# File 'lib/yowl/util.rb', line 16 def repository return @schema.repository end |
#short_name ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/yowl/util.rb', line 54 def short_name() name = @schema.prefixedUri(uri) prefix = name.sub(/:.*/, '') # # If the short name looks like this then fix it a little: # <prefix>:<prefix>-name -> <prefix>:name # name = name.sub(/:#{prefix}-/, ':') return name end |
#to_s ⇒ Object
87 88 89 |
# File 'lib/yowl/util.rb', line 87 def to_s() return short_name() end |
#uri ⇒ Object
20 21 22 |
# File 'lib/yowl/util.rb', line 20 def uri return @resource ? @resource.to_s : nil end |