Class: Gearbox::Vocabulary

Inherits:
RDF::Vocabulary
  • Object
show all
Defined in:
lib/gearbox/vocabulary.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Vocabulary

Returns a new instance of Vocabulary.

Parameters:

  • (RDF::URI, String, #to_s)


93
94
95
96
97
98
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(property, *args, &block) ⇒ Object (protected)



135
136
137
138
139
140
141
# 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

Class Method Details

.[](property) ⇒ RDF::URI

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

Parameters:

Returns:

  • (RDF::URI)


56
57
58
# File 'lib/gearbox/vocabulary.rb', line 56

def [](property)
  RDF::URI.intern([to_s, property.to_s].join(''))
end

.lookup(property) ⇒ Object



60
61
62
# File 'lib/gearbox/vocabulary.rb', line 60

def lookup(property)

end

.property(property, opts = {}) ⇒ void

This method returns an undefined value.

Defines a vocabulary term called ‘property`.

Parameters:

  • (Symbol)


46
47
48
49
# 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

Instance Method Details

#[](property) ⇒ URI

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

Parameters:

Returns:

  • (URI)


105
106
107
# File 'lib/gearbox/vocabulary.rb', line 105

def [](property)
  RDF::URI.intern([to_s, property.to_s].join(''))
end

#inspectString

Returns a developer-friendly representation of this vocabulary.

Returns:

  • (String)


129
130
131
# File 'lib/gearbox/vocabulary.rb', line 129

def inspect
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s)
end

#to_sString

Returns a string representation of this vocabulary.

Returns:

  • (String)


121
122
123
# File 'lib/gearbox/vocabulary.rb', line 121

def to_s
  @uri.to_s
end

#to_uriURI

Returns the base URI for this vocabulary.

Returns:

  • (URI)


113
114
115
# File 'lib/gearbox/vocabulary.rb', line 113

def to_uri
  RDF::URI.intern(to_s)
end