Class: Mida::Vocabulary

Inherits:
Object
  • Object
show all
Defined in:
lib/mida/vocabulary.rb

Overview

Class used to describe a vocabulary

To specify a vocabulary use the following methods: itemtype, has_one, has_many

Direct Known Subclasses

GenericVocabulary

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.propertiesObject (readonly)

Return the properties specification



12
13
14
# File 'lib/mida/vocabulary.rb', line 12

def properties
  @properties
end

.vocabulariesObject (readonly)

Return the registered vocabularies



15
16
17
# File 'lib/mida/vocabulary.rb', line 15

def vocabularies
  @vocabularies
end

Class Method Details

.find(itemtype) ⇒ Object

Find the last vocabulary registered that matches the itemtype



33
34
35
36
37
38
# File 'lib/mida/vocabulary.rb', line 33

def self.find(itemtype)
  @vocabularies.reverse_each do |vocabulary|
    if ((itemtype || "") =~ vocabulary.itemtype) then return vocabulary end
  end
  nil
end

.has_many(*property_names, &block) ⇒ Object

Defines the properties as containing many values If want to say any property name, then use :any as a name Within a block you can use the methods of the class PropertyDesc



65
66
67
# File 'lib/mida/vocabulary.rb', line 65

def self.has_many(*property_names, &block)
  has(:many, *property_names, &block)
end

.has_one(*property_names, &block) ⇒ Object

Defines the properties as only containing one value If want to say any property name, then use :any as a name Within a block you can use the methods of the class PropertyDesc



58
59
60
# File 'lib/mida/vocabulary.rb', line 58

def self.has_one(*property_names, &block)
  has(:one, *property_names, &block)
end

.inherited(subclass) ⇒ Object



40
41
42
# File 'lib/mida/vocabulary.rb', line 40

def self.inherited(subclass)
  register(subclass)
end

.itemtype(regexp_arg = nil) ⇒ Object

Sets the regular expression to match against the itemtype or returns the current regular expression



46
47
48
49
50
51
52
# File 'lib/mida/vocabulary.rb', line 46

def self.itemtype(regexp_arg=nil)
  if regexp_arg
    @itemtype = regexp_arg
  else
    @itemtype
  end
end

.register(vocabulary) ⇒ Object

Register a vocabulary that can be used when parsing, later vocabularies are given precedence over earlier ones



23
24
25
# File 'lib/mida/vocabulary.rb', line 23

def self.register(vocabulary)
  @vocabularies << vocabulary
end

.unregister(vocabulary) ⇒ Object

Un-register a vocabulary



28
29
30
# File 'lib/mida/vocabulary.rb', line 28

def self.unregister(vocabulary)
  @vocabularies.delete(vocabulary)
end