Class: Rust::Manual

Inherits:
Object show all
Defined in:
lib/rust/core/manual.rb

Constant Summary collapse

@@manuals =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description) ⇒ Manual

Returns a new instance of Manual.



34
35
36
37
38
# File 'lib/rust/core/manual.rb', line 34

def initialize(name, description)            
    @name = name
    @description = description
    @voices = {}
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



32
33
34
# File 'lib/rust/core/manual.rb', line 32

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/rust/core/manual.rb', line 31

def name
  @name
end

Class Method Details

.aboutObject



7
8
9
10
11
12
13
14
# File 'lib/rust/core/manual.rb', line 7

def self.about
    puts "Manuals available:"
    @@manuals.each do |category, manual|
        puts "\t- #{manual.name} (:#{category}) → #{manual.description}"
    end
    
    return nil
end

.for(category) ⇒ Object



16
17
18
19
20
21
# File 'lib/rust/core/manual.rb', line 16

def self.for(category)
    category = category.to_sym
    raise "No manual found for '#{category}'." unless @@manuals[category]
    
    return @@manuals[category]
end

.register(category, name, description) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/rust/core/manual.rb', line 23

def self.register(category, name, description)
    category = category.to_sym
    
    @@manuals[category] = Manual.new(name, description)
    
    return nil
end

Instance Method Details

#aboutObject



58
59
60
61
62
63
64
65
66
67
# File 'lib/rust/core/manual.rb', line 58

def about
    puts "****** Manual for #@name ******"
    puts @description
    puts "Voices in manual #@name:"
    @voices.keys.each do |key, matcher|
        puts "\t- #{key}"
    end
    
    return nil
end

#inspectObject



73
74
75
# File 'lib/rust/core/manual.rb', line 73

def inspect
    return "Manual for #@name with #{self.n_voices} voices"
end

#lookup(query) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rust/core/manual.rb', line 40

def lookup(query)
    @voices.each do |key, value|
        if query.match(key[1])
            puts "*** #{key[0]} ***"
            puts value
            return
        end
    end
    
    puts "Voice not found"
    
    return nil
end

#n_voicesObject



54
55
56
# File 'lib/rust/core/manual.rb', line 54

def n_voices
    @voices.size
end

#register(voice, matcher, description) ⇒ Object



69
70
71
# File 'lib/rust/core/manual.rb', line 69

def register(voice, matcher, description)
    @voices[[voice, matcher]] = description
end