class Gearbox::Vocabulary

But with some patterns in mind from patterns.dataincubator.org/book/

Public Class Methods

[](property) click to toggle source

Returns the URI for the term ‘property` in this vocabulary.

@param [#to_s] property @return [RDF::URI]

# File lib/gearbox/vocabulary.rb, line 56
def [](property)
  RDF::URI.intern([to_s, property.to_s].join(''))
end
lookup(property) click to toggle source
# File lib/gearbox/vocabulary.rb, line 60
def lookup(property)

end
new(uri) click to toggle source

@param [RDF::URI, String, to_s]

# File lib/gearbox/vocabulary.rb, line 93
def initialize(uri)
  @uri = case uri
    when RDF::URI then uri.to_s
    else RDF::URI.parse(uri.to_s) ? uri.to_s : nil
  end
end
property(property, opts={}) click to toggle source

Defines a vocabulary term called ‘property`.

@param [Symbol] @return [void]

# File lib/gearbox/vocabulary.rb, line 46
def property(property, opts={})
  metaclass = class << self; self; end
  metaclass.send(:define_method, property) { self.lookup(property) } # class method
end

Protected Class Methods

create(uri) click to toggle source
# File lib/gearbox/vocabulary.rb, line 66
def create(uri) # @private
  @@uri = uri
  self
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/gearbox/vocabulary.rb, line 71
def inherited(subclass) # @private
  @@subclasses << subclass
  unless @@uri.nil?
    subclass.send(:private_class_method, :new)
    @@uris[subclass] = @@uri
    @@uri = nil
  end
  super
end
method_missing(property, *args, &block) click to toggle source
Calls superclass method
# File lib/gearbox/vocabulary.rb, line 81
def method_missing(property, *args, &block)
  if args.empty? && @@uris.has_key?(self)
    self[property]
  else
    super
  end
end

Public Instance Methods

[](property) click to toggle source

Returns the URI for the term ‘property` in this vocabulary.

@param [#to_s] property @return [URI]

# File lib/gearbox/vocabulary.rb, line 105
def [](property)
  RDF::URI.intern([to_s, property.to_s].join(''))
end
inspect() click to toggle source

Returns a developer-friendly representation of this vocabulary.

@return [String]

# File lib/gearbox/vocabulary.rb, line 129
def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s)
end
to_s() click to toggle source

Returns a string representation of this vocabulary.

@return [String]

# File lib/gearbox/vocabulary.rb, line 121
def to_s
  @uri.to_s
end
to_uri() click to toggle source

Returns the base URI for this vocabulary.

@return [URI]

# File lib/gearbox/vocabulary.rb, line 113
def to_uri
  RDF::URI.intern(to_s)
end

Protected Instance Methods

method_missing(property, *args, &block) click to toggle source
# File lib/gearbox/vocabulary.rb, line 135
def method_missing(property, *args, &block)
  if args.empty?
    self[property]
  else
    raise ArgumentError.new("wrong number of arguments (#{args.size} for 0)")
  end
end