Class: ContentsGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContentsGenerator



8
9
10
11
12
# File 'lib/contents_generator.rb', line 8

def initialize
  @command = ARGV.shift
  @argv = ARGV
  @commands = get_commands
end

Class Method Details

.bootObject



14
15
16
# File 'lib/contents_generator.rb', line 14

def self.boot
  new.switch
end

Instance Method Details

#get_commandsObject



26
27
28
29
30
31
32
# File 'lib/contents_generator.rb', line 26

def get_commands
  commands = []
  Dir.entries(CG_LIB).each do |file|
    commands << file.gsub!('.rb', '') if file =~ /rb/
  end
  commands
end

#switchObject



18
19
20
21
22
23
24
# File 'lib/contents_generator.rb', line 18

def switch 
  if @commands.include? @command
    exec("ruby #{CG_LIB}/#{@command}.rb #{@argv.join(' ')}")
  else
    puts OptionParser.new("Usage: cg [#{@commands.join('|')}]").help
  end
end