Class: RTMHelp

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

Instance Method Summary collapse

Constructor Details

#initializeRTMHelp

Returns a new instance of RTMHelp.



5
6
7
# File 'lib/help.rb', line 5

def initialize
    @doc = XML::Document.file('../doc/rtm_help.xml').root
end

Instance Method Details

#get_help(command = '') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/help.rb', line 9

def get_help(command='')
    return get_overview if command == ''
    @doc.find('command').to_a.each {|cmd|
        if cmd['name'].split('|').include? command
            help_text = cmd.find('desc').first.content.gsub!('  ', ' ')
            help_text.gsub!('\n', ' ')
            return make_fancy(help_text)
        end
    }
    "This is not a command.\n"
end

#get_overviewObject



21
22
23
24
25
26
27
28
# File 'lib/help.rb', line 21

def get_overview
    out = "    COMMAND OVERVIEW\n"
    @doc.find('command').to_a.each {|cmd|
        out += '    ' + cmd['name'].gsub('|', ', ').ljust(20) +
                cmd.find('short').first.content + "\n"
    }
    out
end

#make_fancy(text) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/help.rb', line 30

def make_fancy(text)
    out = '    '; count = 0
    text.split(' ').each {|chunk|
        count += chunk.length
        if count >= 60 # new line
            out += "\n    #{chunk} "
            count = chunk.length
        else # append
            out += "#{chunk} "
        end
    }
    out += "\n"
end