Class: Gloo::Core::Dictionary
- Inherits:
-
Object
- Object
- Gloo::Core::Dictionary
- Includes:
- Singleton
- Defined in:
- lib/gloo/core/dictionary.rb
Instance Attribute Summary collapse
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#objs ⇒ Object
readonly
Returns the value of attribute objs.
-
#verbs ⇒ Object
readonly
Returns the value of attribute verbs.
Instance Method Summary collapse
-
#find_obj(word) ⇒ Object
Find the object type by name.
-
#find_verb(verb) ⇒ Object
Find the verb by name.
-
#get_obj_types ⇒ Object
Get the list of verbs, sorted.
-
#get_verbs ⇒ Object
Get the list of verbs, sorted.
-
#init ⇒ Object
Initialize verbs and objects in the dictionary.
-
#initialize ⇒ Dictionary
constructor
Set up the object dictionary.
-
#lookup_keyword(key) ⇒ Object
Lookup the keyword by name or shortcut.
-
#obj?(word) ⇒ Boolean
Is the given word an object type?.
-
#register_obj(subclass) ⇒ Object
Register an object type.
-
#register_verb(subclass) ⇒ Object
Register a verb.
-
#show_keywords ⇒ Object
Show a list of all keywords.
-
#verb?(word) ⇒ Boolean
Is the given word a verb?.
Constructor Details
#initialize ⇒ Dictionary
Set up the object dictionary.
19 20 21 22 23 24 25 |
# File 'lib/gloo/core/dictionary.rb', line 19 def initialize @verbs = {} @objs = {} @verb_references = [] @obj_references = [] @keywords = [] end |
Instance Attribute Details
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
14 15 16 |
# File 'lib/gloo/core/dictionary.rb', line 14 def keywords @keywords end |
#objs ⇒ Object (readonly)
Returns the value of attribute objs.
14 15 16 |
# File 'lib/gloo/core/dictionary.rb', line 14 def objs @objs end |
#verbs ⇒ Object (readonly)
Returns the value of attribute verbs.
14 15 16 |
# File 'lib/gloo/core/dictionary.rb', line 14 def verbs @verbs end |
Instance Method Details
#find_obj(word) ⇒ Object
Find the object type by name.
62 63 64 65 66 67 |
# File 'lib/gloo/core/dictionary.rb', line 62 def find_obj( word ) return nil unless word return nil unless obj?( word ) return @objs[ word.downcase ] end |
#find_verb(verb) ⇒ Object
Find the verb by name.
81 82 83 84 85 86 |
# File 'lib/gloo/core/dictionary.rb', line 81 def find_verb( verb ) return nil unless verb return nil unless verb?( verb ) return @verbs[ verb.downcase ] end |
#get_obj_types ⇒ Object
Get the list of verbs, sorted.
91 92 93 |
# File 'lib/gloo/core/dictionary.rb', line 91 def get_obj_types return @obj_references.sort { |a, b| a.typename <=> b.typename } end |
#get_verbs ⇒ Object
Get the list of verbs, sorted.
98 99 100 |
# File 'lib/gloo/core/dictionary.rb', line 98 def get_verbs return @verb_references.sort { |a, b| a.keyword <=> b.keyword } end |
#init ⇒ Object
Initialize verbs and objects in the dictionary.
44 45 46 47 48 |
# File 'lib/gloo/core/dictionary.rb', line 44 def init $log.debug 'initializing dictionaries' init_verbs init_objs end |
#lookup_keyword(key) ⇒ Object
Lookup the keyword by name or shortcut. Return the keyword (name) or nil if it is not found.
106 107 108 109 110 111 112 113 114 |
# File 'lib/gloo/core/dictionary.rb', line 106 def lookup_keyword( key ) v = find_verb key return v.keyword if v o = find_obj key return o.typename if o return nil end |
#obj?(word) ⇒ Boolean
Is the given word an object type?
53 54 55 56 57 |
# File 'lib/gloo/core/dictionary.rb', line 53 def obj?( word ) return false unless word return @objs.key?( word.downcase ) end |
#register_obj(subclass) ⇒ Object
Register an object type.
37 38 39 |
# File 'lib/gloo/core/dictionary.rb', line 37 def register_obj( subclass ) @obj_references << subclass end |
#register_verb(subclass) ⇒ Object
Register a verb.
30 31 32 |
# File 'lib/gloo/core/dictionary.rb', line 30 def register_verb( subclass ) @verb_references << subclass end |
#show_keywords ⇒ Object
Show a list of all keywords. This includes verbs and objects, names and shortcuts.
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/gloo/core/dictionary.rb', line 120 def show_keywords str = '' @keywords.sort.each_with_index do |k, i| str << k.ljust( 20, ' ' ) if ( ( i + 1 ) % 6 ).zero? puts str str = '' end end end |
#verb?(word) ⇒ Boolean
Is the given word a verb?
72 73 74 75 76 |
# File 'lib/gloo/core/dictionary.rb', line 72 def verb?( word ) return false unless word return @verbs.key?( word.downcase ) end |