Class: ManParser

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

Class Method Summary collapse

Class Method Details

.available_commandsObject



2
3
4
# File 'lib/man_parser.rb', line 2

def self.available_commands
  `ls #{root}`.split("\n").map{|c| c.sub('.1.gz','')}
end

.parse(cmd) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/man_parser.rb', line 10

def self.parse(cmd)
  sections = sections(source(cmd))
  return {} if not sections['OPTIONS'] and not sections['DESCRIPTION']
  description, options = find_options(sections['OPTIONS']||sections['DESCRIPTION'])
  description = sections['DESCRIPTION'] if description.to_s.empty?
  options = parse_options(options)
  {:description => description.map{|l|l.strip}.join(''), :options=>options, :sections=>sections}
end

.source(cmd) ⇒ Object



6
7
8
# File 'lib/man_parser.rb', line 6

def self.source(cmd)
  `gzip -dc #{root}/#{cmd}.1.gz`
end